Page 1 of 1

assistance required with the code <mysql_insert_id()>

Posted: Wed Mar 19, 2008 1:48 pm
by raazaq
Hi,

I wonder if anyone can help me plz... I am new to this forum and am trying to figure out what's wrong with the code. I have got two tables customer and regcustomer and trying to insert data into them. Customer id is the (Pk) of customer table. I am assuming 'mysql_insert_id()' is not working and when I run this script, following error appears on the screen 'Duplicate entry '0' for key 1'.

Code is as below:

Code: Select all

 
$sql1 = "INSERT INTO customer  (customerid, name, telephone, email, address, zip) VALUES ('','$name', '$telephone', '$email', '$address', '$zipcode')";
mysql_query( $sql1 )or die(mysql_error());
 
$sql2 = "INSERT INTO regcustomer (username, password) VALUES ('$username', '$password', mysql_insert_id())";
mysql_query( $sql2 ) or die(mysql_error());
 
Any suggestions...please?

Re: assistance required with the code <mysql_insert_id()>

Posted: Wed Mar 19, 2008 2:10 pm
by impulse()
It means you have a primary key set in one of your columns and you're trying to insert a value into that column that already exists.