Jump to content

ASP code value to another table


Recommended Posts

Hi, another problem with my Charon cart

I've got to the checkout and I can add my order details (OrderID etc etc)

My tables in ms access are the following:

Orders table:

OrderID(primary key created during asp coding)

OrderDetails table:

OrderDetailsID (autonumber, primary key)

OrderID (text, linked one to many with Orders.OrderID)

etc etc

When I try to do the function on the page, it will only add the OrderID to the OrderDetails table if it's the OrderDetails field is set to text and it's the primary key! (Thus removing the relationship between the two tables)

Have also allowed session variables in my browser

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="inc_CharonCart.asp" -->

<script language="javascript" runat="server">

function GetTimeInMillisec()

{

    var Now = new Date()

    var TimeStamp = Now.getTime()

    return TimeStamp

}

</script>

<!--#include file="Connections/searching.asp" -->

<%

Dim Recordset1__var

Recordset1__var = "1"

If (CCcart_Subtotal <> "") Then

  Recordset1__var = CCcart_Subtotal

End If

%>

<%

Dim Recordset1

Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")

Recordset1.ActiveConnection = MM_searching_STRING

Recordset1.Source = "SELECT *  FROM postage  WHERE MinCost <= " + Replace(Recordset1__var, "'", "''") + " AND MaxCost > " + Replace(Recordset1__var, "'", "''") + ""

Recordset1.CursorType = 0

Recordset1.CursorLocation = 2

Recordset1.LockType = 1

Recordset1.Open()

Recordset1_numRows = 0

%>

<%

Dim rsOrders

Dim rsOrders_numRows

Set rsOrders = Server.CreateObject("ADODB.Recordset")

rsOrders.ActiveConnection = MM_searching_STRING

rsOrders.Source = "SELECT top 1 OrderID, SubTotal, PP, GrandTotal  FROM Orders"

rsOrders.CursorType = 0

rsOrders.CursorLocation = 2

rsOrders.LockType = 3

rsOrders.Open()

rsOrders_numRows = 0

%>

<%

Dim rsOrderDetails

Dim rsOrderDetails_numRows

Set rsOrderDetails = Server.CreateObject("ADODB.Recordset")

rsOrderDetails.ActiveConnection = MM_searching_STRING

rsOrderDetails.Source = "SELECT top 1 OrderID, ProductID, ProductName, UnitPrice, Quantity  FROM OrderDetails"

rsOrderDetails.CursorType = 0

rsOrderDetails.CursorLocation = 2

rsOrderDetails.LockType = 3

rsOrderDetails.Open()

rsOrderDetails_numRows = 0

%>

<%

'

'Add shipping from a value in a recordset

'The recordset may be pre-filtered based on the CCcart_SubTotal value

'

if not Recordset1.eof then

CCcart_Shipping=Recordset1("PostCost")

end if

%>

<%

'

'Insert record into Orders recordset when form is submitted

'and store the unique OrderID

'

CC_OrderAction=Request.ServerVariables("SCRIPT_NAME")

if Request("CC_OrderInsert") <> "" then

TimeKey=GetTimeInMillisec()

rsOrders.AddNew

rsOrders("OrderID")=TimeKey

For Each fld in rsOrders.Fields

if Len(Request(fld.Name)) > 0 then

fld.Value = Request(fld.Name)

end if

Next

rsOrders.Update

rsOrders.Requery

rsOrders.Filter= "OrderID='" & TimeKey & "'"

if rsOrders.eof = false then Session("OrderID")

end if

%>

<%

'

'**Save cart to OrderDetails table in Database**

'

if Request("CC_OrderInsert") <> "" then

'Bindingvalues=("ProductID,Quantity,ProductName,UnitPrice,")

UniqueIdValue=Session("OrderID")

UniqueIdColumn="OrderID"

CC_RedirectURL="checkout2.asp"

sub SaveToDatabase(ODRecordset)

ODRecordset.AddNew

ODRecordset.Fields(UniqueIdColumn)=UniqueIdValue

ODRecordset.Fields("ProductID")=CCcart(CC_ProductID,i)

ODRecordset.Fields("Quantity")=CCcart(CC_Quantity,i)

ODRecordset.Fields("ProductName")=CCcart(CC_Name,i)

ODRecordset.Fields("UnitPrice")=CCcart(CC_Price,i)

rsOrderDetails.Update

end sub

for i=0 to ubound(CCcart,2)

if CCcart(CC_ProductID,i) <> "" then

Call SaveToDatabase(rsOrderDetails)

end if

next

Response.Redirect "search2.asp"

end if

%>

rsOrders gets the OrderID from Orders

rsOrderDetails gets all the fields from OrderDetails (except for OrderDetailID as it's an autonumber)

If anyone could help me out as to why it will only allow it when it's in the OrderDetailsID field that would be great.

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...