Having problem with timeslot coding
Posted: Sat Dec 17, 2011 7:23 am
hi guys,i'm beginner in php and i'm here to ask for ur helps.currently i try to develop a system that has a booking system(have timeslot). The code i wrote has some errors that i cannot solve. I try to fix it many times and look for many examples but still stuck.can u guys have a look for my code?hope you willing to help me. Thank you! 
//This for displaying day from Monday until Sunday.
//This for displaying day from Monday until Sunday.
Code: Select all
<html>
<head>
<script language="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=0,width=600,height=500,left = 633,top = 334');");
}
// End -->
</script>
</head>
<body>
<center><table border='1' width='500'; height='300';>
<tr>
<td><h2><center> Choose Timeslot <center></h2>
<?php
echo"<center><table border='1'>";
echo"<tr>";
echo"<td style=background-color:yellow;><a href=javascript:popUp('/Gymnasium//timeslot.php?day=Mon&id=" . $_GET['id'] . "')>Monday</a></td>";
echo"<td style=background-color:#99FF00;><a href=javascript:popUp('/Gymnasium/timeslot.php?day=Tue&id=" . $_GET['id'] . "')>Tuesday</a></td>";
echo"<td style=background-color:#CC6699;><a href=javascript:popUp('/Gymnasium/timeslot.php?day=Wed&id=" . $_GET['id'] . "')>Wednesday</a></td>";
echo"<td style=background-color:#33FFCC;><a href=javascript:popUp('/Gymnasium/timeslot.php?day=Thu&id=" . $_GET['id'] . "')>Thursday</a></td>";
echo"<td style=background-color:#CC6600;><a href=javascript:popUp('/Gymnasium/timeslot.php?day=Fri&id=" . $_GET['id'] . "')>Friday</a></td>";
echo"<td style=background-color:#0099CC;><a href=javascript:popUp('/Gymnasium/timeslot.php?day=Sat&id=" . $_GET['id'] . "')>Saturday</a></td>";
echo"<td style=background-color:#FF66FF;><a href=javascript:popUp('/Gymnasium/timeslot.php?day=Sun&id=" . $_GET['id'] . "')>Sunday</a></td>";
echo"</tr>";
echo"</table></center>";
?>
</td>
</tr>
</center></table>
</body>
</html>
[b]//Next process is to check and choose multiple timeslot in one time.[/b]
[b]//How to check multiple data and submit into database?[/b]
[b]the data i want to submit are package name, date chosen, day chosen and timeslot chosen.[/b]
[b]The system must be able to tell the user either the timeslot is full or not.The limit i want to put is 5 slot per day.[/b]
<?php
require_once('config.php');
?>
<html>
<head>
<title>Choose TimeSlot</title>
<h4><center>TimeSlot</center></h4>
</head>
<?php
$tomorrow = @$_GET['day'];
echo"<form method=post action=timeslot_chosen.php>";
for($tambah = 0; $tambah <= 30; $tambah++)
{
$tomorrow = mktime(0, 0, 0, date("m"), date("d") + $tambah, date("y"));
if(date("D" , $tomorrow) == $_GET['day'])
{
echo date(" d/m/y, D" , $tomorrow) . '<br/>';
$x= 1;
if($_GET['id'] == 1)
{
$query="SELECT * from timeslot WHERE name='package A' AND day='" . $_GET['day'] . "'";
$result=mysql_query($query);
if(!$result)
die("invalid query:".mysql_error());
else
{
while($row=mysql_fetch_array($result,MYSQL_BOTH))
{
[color=#FF0000]// echo"<br><td>".$row[2]."<input type='checkbox' name='check'[]></td><br><br>";[/color]
$x++;
}
}
}
if($_GET['id']== 2)
{
$query="SELECT * from timeslot WHERE name='package B' AND day='" .$_GET['day']."'";
$result=mysql_query($query);
if(!$result)
die("invalid query:".mysql_error());
else
{
while($row=mysql_fetch_array($result,MYSQL_BOTH))
{
[color=#FF0000] // echo"<td>".$row[2]."<input type='checkbox' name='check'[]></td><br><br>";[/color]
$x++;
}
}
}
if($_GET['id']== 3)
{
$query="SELECT * from timeslot WHERE name='package C' AND day='" .$_GET['day']."'";
$result=mysql_query($query);
if(!$result)
die("invalid query:".mysql_error());
else
{
while($row=mysql_fetch_array($result,MYSQL_BOTH))
{
[color=#FF0000]// echo"<td>".$row[2]."<input type='checkbox' name='check'[]></td><br><br>";[/color]
$x++;
}
}
}
if($_GET['id']== 4)
{
$query="SELECT * from timeslot WHERE name='package D' AND day='" .$_GET['day']. "'";
$result=mysql_query($query) or die('try');
if(!$result)
die("invalid query:".mysql_error());
else
{
while($row=mysql_fetch_array($result,MYSQL_BOTH))
{
[color=#FF0000]// echo"<td>".$row[2]."<input type='checkbox' name='check'[]></td><br><br>";[/color]
$x++;
}
}
}
}
}
echo"<input type='submit' value='submit'>";
echo"</input>";
echo"</form>";
?>
</html>
[b]//This is process for to insert data into database[/b]
[b]//I dont know how to insert data(package name,date, day and timeslot) that have been checked above into database.Other word is All data must insert into database in one time.[/b]
//The last question is how to create a "limitation" for timeslot?for example, slot for Monday (17/12/2011) only can be choosen by 5 person only. After that the system will the user that that timeslot is full.Please choose another timeslot.
<?php
require_once('config.php');
$check1 = mysql_escape_string(@$_POST['check1']);
mysql_query("INSERT into timeslot_chosen");
echo"no data inserted";
?>