renesis Posted November 30, 2005 Share Posted November 30, 2005 Hi all. I'm new to this forum and hope to find the solution to my problem. What my problem is... I have created a web site in php-mysql-apache. It deals with online product orders. Assume there are 2 tables, "products" and "orders". Assume that a customer selects some products and pressing "checkout" button the list of the selected products appears. I need to capture the product details and insert them to the "orders" table but it fails. I use the following code: <?php mysql_connect("$host","$user","$pass"); mysql_select_db("$database"); mysql_query("insert into orders values (now(), '', '', '', item_code='$code_no', '', '', '', '')") or die(mysql_error()); ?> I explain: now() is the date today. item_code is the column in "orders" table and "code_no" is the column in "products" table. I use "" because at the moment I'm not interested in these columns. What I get from this code in the "orders" table is the correct date in the "order_date" column and a "1" in the "item_code" column. How did this "1" come from? Any obvious mistakes? Any proposal? Many thanks in advance. Link to comment https://forums.phpfreaks.com/topic/2958-cannot-perform-entry/ Share on other sites More sharing options...
Honoré Posted November 30, 2005 Share Posted November 30, 2005 [!--quoteo(post=323245:date=Nov 30 2005, 01:43 PM:name=renesis)--][div class=\'quotetop\']QUOTE(renesis @ Nov 30 2005, 01:43 PM) 323245[/snapback][/div][div class=\'quotemain\'][!--quotec--] I use the following code: <?php mysql_connect("$host","$user","$pass"); mysql_select_db("$database"); mysql_query("insert into orders values (now(), '', '', '', item_code='$code_no', '', '', '', '')") or die(mysql_error()); ?> Any obvious mistakes? Any proposal? try this mysql_query("insert into orders values (now(), '', '', '', $code_no, '', '', '', '')") or mysql_query("insert into orders values (now(), '', '', ''," . $code_no . ", '', '', '', '')") Link to comment https://forums.phpfreaks.com/topic/2958-cannot-perform-entry/#findComment-9948 Share on other sites More sharing options...
renesis Posted November 30, 2005 Author Share Posted November 30, 2005 Thanks for the reply. When I try the first one, I get an error: You have an error in your SQL syntax near ' '', '', '', '')' When I try the second one I do not get eny errors but an empty entry is created (no value in "orders" table). Link to comment https://forums.phpfreaks.com/topic/2958-cannot-perform-entry/#findComment-9950 Share on other sites More sharing options...
manmadareddy Posted November 30, 2005 Share Posted November 30, 2005 I hope you have made "item_code" as primary key. Please remove it . Link to comment https://forums.phpfreaks.com/topic/2958-cannot-perform-entry/#findComment-9952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.