Reputation: 141
(My First language is not English) i'm inserting new data to mysql but i want to take added data's id in same page.
for example: (im using auto increment)
$sql = "INSERT INTO example (name) VALUES ('$name')";
$query = mysql_query($sql,connectDB());
if ($query)
{
return /*added data id*/;
}
How i do?
Upvotes: 3
Views: 64
Reputation: 270609
Just call mysql_insert_id()
to return the most recently created id.
if ($query)
{
echo mysql_insert_id();
}
Upvotes: 4