Jump to content


Photo

Cannot perform entry


  • Please log in to reply
3 replies to this topic

#1 renesis

renesis
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 November 2005 - 11:43 AM

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.

#2 Honoré

Honoré
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationAntwerp - Belgium

Posted 30 November 2005 - 12:04 PM

[!--quoteo(post=323245:date=Nov 30 2005, 01:43 PM:name=renesis)--][div class=\'quotetop\']QUOTE(renesis @ Nov 30 2005, 01:43 PM) View Post[/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?
[/quote]
try this
mysql_query("insert into orders values (now(), '', '', '', $code_no, '', '', '', '')")
or
mysql_query("insert into orders values (now(), '', '', ''," . $code_no . ", '', '', '', '')")


#3 renesis

renesis
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 November 2005 - 12:47 PM

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).

#4 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 30 November 2005 - 12:56 PM

I hope you have made "item_code" as primary key.
Please remove it .




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users