MySQL insert query inside a for loop

Hello, everyone. I am a novice PHP user, but I’ve got a task to create a simple hotel booking system. It consists of several steps, each one of which is described in a separate .php files. All the files seem to be working fine, except the last one which takes all the data from the forms in previous files and inserts them into a database table. I’m trying to create a for-loop which would create a record for each day a gues is staying in a hotel. I checked all the variables by echo-ing them and they all are fine. I also tried the INSERT query without a loop and it works as well. So i guess there is something wrong with the loop. Here it is:
[php]<?php
session_start();
include(‘db_config.php’);
$name=($_POST[‘name’]);
$telephone=addslashes($_POST[‘telephone’]);
$email=addslashes($_POST[‘email’]);
$code=md5($email.time());
$checkout_date=$_SESSION[‘checkout’];
$checkin_unix=$_SESSION[‘checkin_unix’];
$checkout_unix=$_SESSION[‘checkout_unix’];
$roomtype=$_SESSION[‘roomtype’];
$checkin_date=$_SESSION[‘checkin’];
for ($stay_date=$checkin_unix; ; $stay_date=$stay_date+246060) {
if ($stay_date=$checkout_unix){
break;
}
mysql_query(“INSERT INTO reservations VALUES(
‘’,
‘$roomtype’,
‘pending’,
‘date (‘d/m/Y’, $stay_date)’,
‘$stay_date’,
‘$checkout_date’,
‘$name’,
‘$telephone’,
‘$email’,
‘$code’
)”);

}

?>[/php]

I would be very grateful for any kind of help.

I Think you are going to need a while loop, not a for

Sponsor our Newsletter | Privacy Policy | Terms of Service