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);

?>
$insert=("INSERT INTO bookings (ID, eventID, username, ntickets) VALUES (NULL, $a, [B]$usrname[/B], $b");
mysql_query($insert) or die ('Error');

}
mysql_close($conn);

?>

TYPO?! Shouldn't it be $username

r u getting any error. clearly mention .

Jesus christ.

Sorry, I Haven't slept in 3 days.

I've fixed the typo however the script still isnt working.

$insert=("INSERT INTO bookings (ID, eventID, username, ntickets) VALUES (NULL, $a, $username, $b");
mysql_query($insert) or die ('Error');

Isn't adding to my database and not sure as to why

Jesus christ.

Sorry, I Haven't slept in 3 days.

I've fixed the typo however the script still isnt working.

$insert=("INSERT INTO bookings (ID, eventID, username, ntickets) VALUES (NULL, $a, $username, $b");
mysql_query($insert) or die ('Error');

Isn't adding to my database and not sure as to why

I know that feeling...

Ok try this

$insert=("INSERT INTO bookings (ID, eventID, username, ntickets) VALUES (NULL, '$a', '$username', '$b')");
mysql_query($insert) or die ('Error');

Hope it helps...

No Worries, Don't forget to mark the post as solved ;)

Cheers...

One more thing actually:

The following scripts should take a user booking an event an add it to my booking table however its only adding the username and the other fields are blank:


book.php

<?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', '$username', '$b')");
mysql_query($insert) or die ('Error');

}
mysql_close($conn);

?>
<html>
<body>
</br>
<a href ="index.php" /> Retun to Home page</a> 
</html>
</body>

booking.php

<?php

$conn = mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("") or die(mysql_error());

$a=$_GET["ID"];

echo "<form method='post' action='book.php' >";
echo "Quantity of tickets: <input name ='ntickets'/>";
echo "<input type ='hidden' name='ID' value='$a'/>";
echo "<input type='submit' value='Go!' />";
echo "</form>";


?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.