cart checkout sql query problem

Discussion in 'PHP' started by Kyriakos, May 22, 2008.

  1. #1
    hi,

    i have a shopping cart. in checkout page some sql queries doesn't working.
    <?php if ($checkout == "yes") {
    
    $sql="INSERT INTO header (fullname, address, city, post_code, phone, mobile, payment, remarks, ordate, sessionid)
    VALUES ('$_POST[fullname]', '$_POST[address]', '$_POST[city]', '$_POST[post_code]', '$_POST[phone]', '$_POST[mobile]', '$_POST[payment]', '$_POST[remarks]', '$_POST[ordate]', '$sessionid')";
    
    $result = mysql_query("SELECT * FROM cart WHERE sessionid='$sessionid'");
    
    $result2 = mysql_query("SELECT orderid FROM header WHERE sessionid='$sessionid' ORDER BY orderid desc");
    
    $sql2="INSERT INTO details (orderid, code, qty, pricer) VALUES ('".$orderid."', '".$code."', '".$qty."', '".$pricer."')";
    
    
    mysql_query("DELETE FROM cart WHERE sessionid='$sessionid'");
    
    echo "record ok";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    mysql_close($con);
    ?><?php } ?>
    PHP:
    the first SQL query is working only (INSERT INTO header).

    can anybody help me?
     
    Kyriakos, May 22, 2008 IP
  2. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    in asp code:
    sqlheader="insert into header (fullname, address, city, post_code, phone, mobile, payment, remarks, ordate, sessionid) VALUES ('"&fullname&"','"&address&"','"&city&"','"&post_code&"','"&phone&"','"&mobile&"','"&payment&"','"&remarks&"','1','"&ordate&"','"&sessionid&"')"
    
    	con2.execute sqlheader
    
    	sqlselfromCart="select * from cart where sessionid='"&session.sessionid&"'"
    	set ordersRS=con.execute(sqlselfromcart)
    
    	sqlselfromheader="select orderid from header where sessionid='"&session.SessionID&"' order by orderid desc"
    	set orderidRS=con2.execute(sqlselfromheader)
    
    	orderid=orderidRS("orderid")
    	'response.write(orderid)
    
    
    
    	WHILE NOT ordersRS.EOF
    
    
    
    	code=ordersRS("code")
    	qty=ordersRS("qty")
    	pricer=ordersRS("pricer")
    
    
    
    
    
    	sqlInsertIntoDetails="insert into details (orderid,code,qty,pricer) VALUES ('"&orderid&"','"&code&"','"&qty&"','"&pricer&"')"
    	con2.execute sqlInsertIntoDetails
    	response.Write("record ok!")%><br><%
    
    	ordersRS.MoveNext
    	WEND
    PHP:
     
    Kyriakos, May 22, 2008 IP