Timms
02-28-2013, 11:05 PM
My form consists of a "select amount of people" select menu,
a select menu to select the hour,
and a date select menu,
What is meant to happen:
the user selects how many people is meant to be booked in and which hour of the day they are booking in, each person gets booked in for 1 hour each,
so if they were booking in 3 people that is 3 hours they are booking in for, from the hour of the day selected, so if someone books in 3 people at 3pm that books in from 3 tell 6 so (3pm 4pm 5pm)
so using a for statement i grab these times to prepare them to be added to the mysql data-base to make these times booked so no one else can book these times on this date. So how would i add these to a mysql data-base using a for statement?
here is my code:
compdate is the day of the month then the month completed how it should be,
i made the hour -1 so when it adds it adds the correct time because when it runs the for tag its always +1
$compdate = $listday . "/" . $listmonth;
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$result=mysql_query($sql);
$listhour = $listhour-1;
for($i = 0; $i > $people; $i++)
{
//echo $i+1 . " ";
$listhour = $listhour+1;
$newtimes = $listhour . " " . $listampm;
$sql="INSERT INTO $tbl_name(dates, times)VALUES('$compdate', '$newtimes')";
if($result){
echo "$newtimes Success!";
}
else {
echo "$newtimes ERROR";
}
mysql_close();
}
//check if query successful
Obviously this looks like it would work but dosent because it wont run the mysql correctly and insert it to the data-base, a bit of sloppy code which i need help, so it adds all the times to the mysql that have been booked in.
Apologies if this is a MySQL question i couldn't figure out if it was a MySQL rather than a php because it uses the for tag i leaned more to that php side of things or at least that's how it seems to me :eek:
Help is appreciated im really stuck on this!
Thanks
a select menu to select the hour,
and a date select menu,
What is meant to happen:
the user selects how many people is meant to be booked in and which hour of the day they are booking in, each person gets booked in for 1 hour each,
so if they were booking in 3 people that is 3 hours they are booking in for, from the hour of the day selected, so if someone books in 3 people at 3pm that books in from 3 tell 6 so (3pm 4pm 5pm)
so using a for statement i grab these times to prepare them to be added to the mysql data-base to make these times booked so no one else can book these times on this date. So how would i add these to a mysql data-base using a for statement?
here is my code:
compdate is the day of the month then the month completed how it should be,
i made the hour -1 so when it adds it adds the correct time because when it runs the for tag its always +1
$compdate = $listday . "/" . $listmonth;
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$result=mysql_query($sql);
$listhour = $listhour-1;
for($i = 0; $i > $people; $i++)
{
//echo $i+1 . " ";
$listhour = $listhour+1;
$newtimes = $listhour . " " . $listampm;
$sql="INSERT INTO $tbl_name(dates, times)VALUES('$compdate', '$newtimes')";
if($result){
echo "$newtimes Success!";
}
else {
echo "$newtimes ERROR";
}
mysql_close();
}
//check if query successful
Obviously this looks like it would work but dosent because it wont run the mysql correctly and insert it to the data-base, a bit of sloppy code which i need help, so it adds all the times to the mysql that have been booked in.
Apologies if this is a MySQL question i couldn't figure out if it was a MySQL rather than a php because it uses the for tag i leaned more to that php side of things or at least that's how it seems to me :eek:
Help is appreciated im really stuck on this!
Thanks