mysql_insert_id() not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chopWood
Forum Commoner
Posts: 45
Joined: Fri Apr 30, 2010 9:28 am

mysql_insert_id() not working

Post 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
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: mysql_insert_id() not working

Post 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?
chopWood
Forum Commoner
Posts: 45
Joined: Fri Apr 30, 2010 9:28 am

Re: mysql_insert_id() not working

Post 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...
Post Reply