Click to See Complete Forum and Search --> : Retrieving ID field from the database?


k4v
06-16-2005, 10:13 AM
I've created a database in which each member signs up and the ID field (which increments automatically) acts as their membership number. However i now need to retrieve the ID from the database to put it into an email to send to the members.

Can anyone help?

NogDog
06-16-2005, 10:36 AM
Assume $query contains your SQL insert statement for adding the new member:

$result = mysql_query($query);
if(mysql_affected_rows() == 1)
{
$userID = mysql_insert_id();
}
else
{
# error on insert, handle error reporting here.
}