Hello,
The first part of the script works regarding updating however for some reason and I cant figure out why its not inserting into my bookings table.
Any ideas?
<?php
session_start();
// is the one accessing this page logged in or not?
if (!isset($_SESSION['logged'])
|| $_SESSION['logged'] !== 1) {
// not logged in, move to login page
header('Location: account.html');
exit;
}
?>
<?php
$a = $_POST["ID"];
$b = $_POST["ntickets"];
$username=$_SESSION['user'];
$conn = mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
$result = mysql_query("Select * from events where ID='$a'");
$row = mysql_fetch_array($result);
if( $row["availability"]<$b)
{
echo " Out of stock!" ;
}
else
{
mysql_query ("UPDATE events SET availability = availability - $b WHERE ID = $a ");
echo " $b Tickets have been booked " ;
$insert=("INSERT INTO bookings (ID, eventID, username, ntickets) VALUES (NULL, $a, $usrname, $b");
mysql_query($insert) or die ('Error');
}
mysql_close($conn);
?>