 |
|
ช่วยหน่อยครับ ทำไมมันถึงไม่เข้าเงื่อนไขที่ 2 อ่ะ ครับ ทั้งๆที่มันเก็บ sessionID ตัวเดียวกัน มันต้องได้ค่า จริง |
|
 |
|
|
 |
 |
|
If rs2.Eof Then CartID=Session.SessionID Product=rs("ID_Product") Name=rs("Name") Price=rs("Price") Quantity=1 Sql2="Insert into Cart(CartID,ID_Product,Name,Price,Quantity) values("&CartID&",'"&Product&"','"&Name&"',"&Price&","&Quantity&")" Set rs2 = Conn.execute(Sql2) Session("BookSum")=Session("BookSum")+1 else if rs2("CartID")=session.sessionID then Product=rs("ID_Product") Name=rs("Name")
Price=rs("Price") Quantity=rs2("Quantity")+1 Sql="Update Cart Set ID_Product=Product,Name=Name,Price=Price,Quantity=Quantity where CartID="&Session.SessionID Set rs2 = Conn.execute(Sql) Session("BookSum")=Session("BookSum")+1 End if
ทำไมมันถึงไม่เข้าเงื่อนไขที่ 2 อ่ะ ครับ ทั้งๆที่มันเก็บ sessionID ตัวเดียวกัน มันต้องได้ค่า จริง แล้วต้องเข้าเงื่อนไข else if อ่ะ แต่เนี้ยมันเข้าเงื่อนไขแรกตลอดเลย ช่วยบอกหน่อยนะครับ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
28 ม.ค. 2548 07:33:24 |
By :
งงเลย |
View :
2684 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต่ออีกนะครับ
คือว่า ตอนแรก เรา insert ข้อมูลเข้าไปก่อนนะครับ แล้ว เสร็จแล้วผมต้องการ update ครับ เลยให้ค่า field CartID เนี้ยมันเท่ากับ sessionID เพราะว่า มันได้ insert เข้าไปแล้ว แต่มันมีปัญหาคือ พอเราจะ add ข้อมูลซ้ำ เพื่อทำการ update มันปรากฏว่ามัน ไปที่เงื่อนไขแรก ครับทั้งๆที่เงื่อนไขแรก ก็บอกอยู่แล้ว ว่า ถ้า มัน Eof มันต้องทำ และมันก็มีข้อมูลอยู่ในฐานข้อมูลครับ เลย งง อ่ะครับ ช่วยหน่อยนะครับ คุณ วิน (เวบมาสเตอร์) หรือ ใครก็ได้ครับที่ช่วยได้ แก้ไขโค๊ดให้ผมหน่อย หรือ บอกแนวทางก็ได้ครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
28 ม.ค. 2548 07:45:52 |
By :
งงเลย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
rs2 = อะไรครับ 
|
 |
 |
 |
 |
Date :
28 ม.ค. 2548 10:45:28 |
By :
ountnaja |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูแล้ว งง ปวดหัวเลย งัก งัก 
|
 |
 |
 |
 |
Date :
28 ม.ค. 2548 10:50:32 |
By :
@W_IN |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
5555555555555 
|
 |
 |
 |
 |
Date :
28 ม.ค. 2548 11:01:54 |
By :
ountnaja |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งั้นเอาโค๊ดไปเต็มๆเลยครับ
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.mapPath("../E_Com.mdb") 'oledb for ado2.0 up only?
Sql="Select * From Cart where CartID=" & Session.SessionID '
Set rs2=Server.CreateObject("ADODB.Recordset")
rs2.Open Sql, Conn, , 3
ID_Product=Request.QueryString("ID_Product")
If ID_Product<>"" Then
Sql="Select * From Product where ID_Product='" & ID_Product & "'" Set rs=Server.CreateObject("ADODB.Recordset")
rs.Open Sql, Conn, 0, 3
rs2.Filter="ID_Product='" & rs("ID_Product") &"'"
If rs2.Eof Then
CartID=Session.SessionID
Product=rs("ID_Product")
Name=rs("Name")
Price=rs("Price")
Quantity=1
Sql2="Insert into Cart(CartID,ID_Product,Name,Price,Quantity) values("&CartID&",'"&Product&"','"&Name&"',"&Price&","&Quantity&")"
Set rs2 = Conn.execute(Sql2)
Session("BookSum")=Session("BookSum")+1
Else
if rs2("CartID")=Session.SessionID then
Product=rs("ID_Product")
Name=rs("Name")
Price=rs("Price")
Quantity=rs2("Quantity")+1
Sql="Update Cart Set ID_Product=Product,Name=Name,Price=Price,Quantity=Quantity where CartID="&Session.SessionID
Set rs2 = Conn.execute(Sql)
Session("BookSum")=Session("BookSum")+1
End if
End if
rs2.Filter=""
rs.close
Set rs=nothing
End If
If Request.Form("calc")<>"" and Not rs2.Eof Then
rs2.MoveFirst
Do While Not rs2.Eof
If Request.Form(rs2("ID_Product"))="on" Then
Session("BookSum")=Session("BookSum")-rs2("Quantity")
rs2.Delete Else
quantity=Request.Form("q" & rs2("ID_Product"))
If CInt(quantity)<>rs2("Quantity") Then
Session("BookSum")=Session("BookSum")+quantity-rs2("Quantity")
rs2("Quantity")=quantity ' update ฟิลด์ quantity
rs2.Update
End If
End If
rs2.MoveNext
Loop
End If
' จ่ายเงิน
If Request.Form("pay")<>"" Then
Response.Redirect "checkout.asp"
End If
ตามข้อมูลที่บอกอ่ะครับ ข้างบน คือมันไม่เข้าเงื่อนไข 2 มันไปเข้าเงื่อนไขแรก ทำให้ add แล้ว ค่า primary key ซ้ำไม่ได้ครับ
|
 |
 |
 |
 |
Date :
28 ม.ค. 2548 11:09:27 |
By :
งงมาก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|