mysql_insert_id() help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
glennn
Forum Newbie
Posts: 3
Joined: Sun Mar 30, 2003 5:13 pm

mysql_insert_id() help

Post by glennn »

i'm passing an AUTO_INC. from one table to the form on the next page using "/page.htm?subscriberID=".$subscriberID and it's passing the variable to the next url correctly, but writing "0" in my table - can someone help, please?


thanks,
glenn
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

Could you givel more details :? There's probably a mistake in query, but I can't tell...
glennn
Forum Newbie
Posts: 3
Joined: Sun Mar 30, 2003 5:13 pm

Post by glennn »

mysql_query($query);
$SubscriberID=mysql_insert_id();
header("Refresh: 0;url=http://www.safe-teen.net/autoreg.php?Su ... bscriberID);

i do this and it once was passing the AUTO_INCREMENTED int friom the first table to the url so i could use it in a second form, but it suddenly started passing "0" always. can't figure out why...

i think it's someting to do with the indices and the primary keys in the tables because i was fooling around with them to make it work before...

thanks
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

If mysql_insert_id() doesn't return a value, there must be something wrong with your database.

Echo the mysql_insert_id() before the refresh and see if there's something (also commnet the header for test purposes). If it doesn't work, try using a database query SELECT LAST_INSERT_ID().
Post Reply