hi guys
im making a ticket order system but having a problem. the problem is that when i enter the quantity it gives me an error saying there are not enough tickets. in the table ive set the ticket amount to 1000. im looking for it to subtract the quantity from the amount in the table
heres a picture:
i have 3 tables. packages, bookings and users
p.s. im a noob at coding lol
http://www.jhscott.net46.net/services.php
that is the link to the page.
im making a ticket order system but having a problem. the problem is that when i enter the quantity it gives me an error saying there are not enough tickets. in the table ive set the ticket amount to 1000. im looking for it to subtract the quantity from the amount in the table
heres a picture:
i have 3 tables. packages, bookings and users
p.s. im a noob at coding lol
http://www.jhscott.net46.net/services.php
that is the link to the page.
PHP:
$packageselect = $_POST['packageselect'];
//echo $packageselect;
$orderedtickets = $_POST['orderedtickets'];
//echo $orderedtickets;
$username = $_COOKIE["username"];
//echo $username;
$con = mysql_connect("host","mylogin","dsadsadqweqwe");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("a7438072_users", $con);
// select firstname from user table
$getname = mysql_query("SELECT firstname FROM users
WHERE username ='$username'");
while($row = mysql_fetch_array($getname))
{
$firstname = $row['firstname'];
//echo $firstname;
}
//// get surname from table
$getname = mysql_query("SELECT surname FROM users
WHERE username ='$username'");
//
while($row = mysql_fetch_array($getname))
{
$surname = $row['surname'];
// echo $surname;
}
//echo $firstname;
// echo $surname;
//echo $packageselect;
//echo $orderedtickets;
// check there is enough tickets
//select total number of tickts to subtract from
$result = mysql_query("SELECT total FROM package
WHERE package ='$packageselect'");
while($row = mysql_fetch_array($result))
{
$totaltickets = $row['total'];
}
if ($orderedtickets > $totaltickets){
echo " sorry there are not enough tickets left";
}else {
// subtracting tickets ordered from the total
$ticketsremaining = $totaltickets - $orderedtickets;
//echo $ticketsremaining;
//put the new totoal in the package table
mysql_query("UPDATE package SET total = '$ticketsremaining'
WHERE package = '$packageselect'");
// put details into booked table
mysql_query ("INSERT INTO bookings (firstname, lastname, package, tickets)
VALUES ('$firstname', '$surname','$packageselect', '$orderedtickets')");
header('Location:orderthanks.html');
}
?>