here's my code

$sql=mysql_query("insert into guest (fname, lname, address, contactno, emailadd) values ('$fname', '$lname', '$country', '$contact', '$mail')");
$search = mysql_query("select * from guest order by code DESC limit 1");
$row = mysql_fetch_array($search);
$lastnum = $row['code'];

$number = $_POST["Rooms"];
$count = count($number);
for ($i=0; $i<$count; $i++)
{
	mysql_query("Insert Into rent (cno, checkin, checkout, noofrooms, roomtype, status, date, 			    username) values ('$lastnum', '$in', '$out', '$room', '$type', 'pending', '$date', 'guest')") or die(mysql_error());
 }
?>

i have a problem if i choose 2 Rooms its only insert 1. how can i insert twice or thrice and more. please help

Looks to me like you are violating your primary key when you try to insert a second record. Make sure that you assign a new PK each time you insert into your Rooms table.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.