Return to Snippet

Revision: 1024
at August 29, 2006 07:15 by deadmoon


Initial Code
$new_sql = "select MAX(id) from reviews";
$get_new_sql= mysql_query($new_sql) or die(mysql_error());
$new_id = mysql_result($get_new_sql,"id");  


<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
?>

Initial URL


Initial Description
two ways of doing it. 2nd is best

Initial Title
Last if of mysql query

Initial Tags
mysql, query

Initial Language
PHP