Get a column value (like id) after mysql INSERT

Rorbywwg

New Member
Can I get from PHP a value back like the new id from the row I've just added to the database or should I make a SELECT to retrieve it?\[code\]<?php$sql = "INSERT INTO my_table (column_1, column_2) VALUES ('hello', 'ciao')";$res = mysql_query ($sql) or die (mysql_error ());$sql = "SELECT column_id FROM my_table WHERE column_1 = 'hello'";$res = mysql_query ($sql) or die (mysql_error ());$row = mysql_fetch_assoc ($res);$id = $row["column_id"];print "my id is = $id";?>\[/code\]
 
Back
Top