Jump to content

Easiest way of moving/copying data


himesh

Recommended Posts

The final step for my website will be for the user to press checkout and the data that was in the cart be either moved or copied to the order table where their username equals to a username that is in the cart. Along with the data that was in the cart, the date must be automatically be added and the orderID must be the same for each item that is to be added into the order table.Which would be the easiest way to go about this? copying the data then straight after deleting it or moving from one table to another (which I couldnt find much on when I googled it)

Link to comment
Share on other sites

I have tried to do copy and then move, it has worked in part.It manages to copy the last item in the cart along with the total price for the order but not the other items in the cart at the time.The delete query works fine.Here is my code.

if ($action == 'checkout') {		mysql_data_seek($cart,0);		while ($row_cart = mysql_fetch_assoc($cart)) {	$addorder = mysql_query("INSERT INTO tblorder (manufacturer, modelnumber, quantity, price, totalprice, date, username)												   VALUES ('$row_cart[manufacturer]', '$row_cart[modelnumber]', '$row_cart[quantity]', '$row_cart[price]', '$total', 'DATE: Auto CURDATE()', '$_SESSION[MM_Username]')");	}		$deletefromcart = mysql_query("DELETE FROM tblcart WHERE username = '$_SESSION[MM_Username]'");}

Link to comment
Share on other sites

I have added a counter which verifies that it runs the required number of times for each item in the cart however when trying to print out what the query is doing, I am getting a syntax error even though I am using the code from the php manual, maybe I have missed something simple.

if ($action == 'checkout') {	$count = 0;		mysql_data_seek($cart,0);		while ($row_cart = mysql_fetch_assoc($cart)) {		$addorder = mysql_query("INSERT INTO tblorder (manufacturer, modelnumber, quantity, price, totalprice, date, username)												   VALUES ('$row_cart[manufacturer]', '$row_cart[modelnumber]', '$row_cart[quantity]', '$row_cart[price]', '$total', 'DATE: Auto CURDATE()', '$_SESSION[MM_Username]')");		$result = mysql_query($addorder);		$count = $count+1;	}	$deletefromcart = mysql_query("DELETE FROM tblcart WHERE username = '$_SESSION[MM_Username]'");		$result1 = mysql_query($deletefromcart);	print $count;if (!$result) {	$message  = 'Invalid query: ' . mysql_error() . "\n";	$message .= 'Whole query: ' . $addorder;	die($message);}if (!$result1) {	$message  = 'Invalid query: ' . mysql_error() . "\n";	$message .= 'Whole query: ' . $deletefromcart;	die($message);}}

Link to comment
Share on other sites

Ive put it back inside the loop and I am getting this, Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 Whole query: 1. I have also placed the other queries within the loop and this is the only result I am getting, when I try and print out the other queries outside of the loop, I am getting the same error. If I press refresh on the error page, I get an error saying that the query is empty.

Link to comment
Share on other sites

So it's your query. Did you try fixing it? Syntax errors mean you wrote it in a way the computer doesn't understand.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...