Page 1 of 1

mysql_insert_id() not working

Posted: Wed Feb 01, 2012 10:04 am
by chopWood
The following INSERT query has an auto_increment field as a primary key. The update DOES take place but the result of mysql_insert_id() is always 0. Any clues why zero?

Code: Select all

$q = "INSERT INTO maaMembers
(last_name,first_name, middle_init, address, city, zip, phone, cell,email,State, registration_date) VALUES ('$ln','$fn', '$mi','$address','$city','$zip', '$phone','$cell','$e','$state', NOW())";
	
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));


echo "ID of last inserted record is: " . mysql_insert_id(); //result is always 0

Re: mysql_insert_id() not working

Posted: Wed Feb 01, 2012 10:40 am
by mikosiko
The following INSERT query has an auto_increment field as a primary key.
which is the DataType for your AUTO_INCREMENT field?
The update DOES take place but the result of mysql_insert_id() is always 0. Any clues why zero?
you mean INSERT? ... are you sure that it is effectively inserting records?

Re: mysql_insert_id() not working

Posted: Thu Feb 02, 2012 2:53 pm
by chopWood
Okay, might as well shoot me now. Here is the statement that I was using for about an hour (as included in the original post title but not the working example):

mysql_insert_id($dbc);

thanks for your help...