how to generate auto number in php?
here's my code in saving a data
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("reservation", $con);
[B]$id=mysql_query("Select * from guest order by code desc");
if ($id == NULL)
{
$id = 1;
}
else
{
$number=$id + 1;
}[/B]
$sql="INSERT INTO guest (code, fname, mname, lname, address, emailadd, contactno)
VALUES ('$number','".$_POST["FirstName"]."','".$_POST["Mname"]."','".$_POST["LastName"]."','".$_POST["Country"]."','".$_POST["Email"]."','".$_POST["Phone"]."')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("reservation", $con);
$sql1="Insert into rent (checkin, checkout, noofrooms, roomtype) VALUES ('".$_POST[ADate]."','".$_POST[AnotherDate]."','".$_POST[Rooms]."','".$_POST[RoomType]."')";
if (!mysql_query($sql1,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
help please :(