MalcolmX
MalcolmX

Reputation: 141

how to i take added data's id? (mysql)

(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

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270609

Just call mysql_insert_id() to return the most recently created id.

if ($query)
{
   echo mysql_insert_id();
}

Upvotes: 4

Related Questions