mysql_insert_id()
Written by: maffelu , 2009-04-17 07:35:57
<?php
//Create a connection
$link = mysql_connect("db.telana.com", "maffelu", "xeno2409");
//Select database
mysql_select_db("examples", $link);
//Create a query
$sql = "INSERT INTO Person (Name, Age, Gender) VALUES ('Olov', 21, 'Male')";
//Execute the query
$result = mysql_query($sql, $link);
if($result)
{
//If correct, output result
echo "The last inserted record has id ".mysql_insert_id();
}
else
{
//If the query was unsucceful, we will output the error
echo "<b>Error ".mysql_errno($link).":</b> ".mysql_error($link);
}
//Close the connection
mysql_close($link);
?>
There are no comments on this article.
If you have any question or just want to leave a message, just fill out the form below!
Your e-mail will not be visible in your post, it is for validation reasons only
Maffelu
Creator and admin of MorkaLork.com.
Started programming in HTML back when frames and tables was the way to design a page, moved on to Pascal/Delphi, PHP, javascript/jQuery, VB.NET/C#, Java and C++.
Currently studies .NET (in general) focusing on ASP.NET.