-
I have a table "Members" with the following 3 fields: userid (int, primary key, auto_increment), email and name.
I use the following line to enter members in the table:
$results = mysql_query("INSERT INTO Members (email,name) VALUES ('$email','$name')");
I never specify the value of the userid field, this is done automatically. But is there a way to know what userid a member received without doing a database search? I need this userid value to enter in another table that contains all the input of the new member.
-
Use this:
PHP Code:
<?php
$userid = mysql_insert_id();
?>
-
PHP Code:
int mysql_insert_id ([int link_identifier])
this will return you auto increment field value from last query executed in script
PHP Code:
$link = mysql_connect ("localhost", "username", "secret")
or die ("Could not connect");
$results = mysql_query("INSERT INTO Members (email,name) VALUES ('$email','$name')");
$id = mysql_insert_id($link);
mysql_close ($link);