I am working on "Bus Reservation Website" that allowed the user to book trips from city to another. I have 128 rout every day. Each rout bus capacity is 44 seat. So i want that when the user click on confirm booking the system will calculate the seats booked on the same day the user selected for the same routs. so if it fully booked message
Sorry no seat available
will be displayed. else the booking will be confirm and number of seats left will be displayed too.
I generated this table in order to count the seats each day and rout: Date table . and my booking table is Booking. Any how, i tried this code to calculate the seat number but it didn't work:
<?php
@session_start();
$username = "root";
$password = "";
$server="localhost";
$database = "Mydatabase";
$table = "booking";
@mysql_connect($server,$username,$password);
mysql_select_db($database);
if(isset($_POST['ok']))
{
//values from my html page
$dept = $_POST['tdep'];
$arr = $_POST['tarr'];
$date = $_POST['ddate'];
$tcode=$_POST['tcode'];
$userid = $_SESSION['login'];
$num =$_POST['num'];
$confirmation = uniqid();
//booking details that will be stored in booking table
$sql = "INSERT INTO $table VALUES('$confirmation','$tcode', '$date', '$num', '$userid', '$price', '$dept','$arr' )";
$query=mysql_query($sql);
//date,rout and number of seats will be inserted to date table
$sql = "INSERT INTO date (tcode,sno,date) VALUES('$tcode', '$num','$date' )";
$query=mysql_query($sql);
//calculating number of seats
$sqld="SELECT COUNT(sno) FROM date WHERE date='$date' AND tcode='$tcode'";
$queryd=mysql_query($sqld);
if ($queryd>44)
echo "No Available Seats left";
else
echo "seats Available= ".$queryd;
//decarsing number of seats in routs table
$sql3 = "UPDATE long_dis SET seat=seat-'$num' WHERE Tcode='$tcode'";
$query3=mysql_query($sql3);
//confirmation message
echo "<h3><font color='red'>Booking is successfully Confirmed for national id :".$userid."</font></h3>";
echo "<h4><font color='blue'>The total cost= ".$price." OMR </br>And your confirmation code is: ". $confirmation."</font></h4>";
}
?>
Thank you for your help in advance,