0

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

?>
3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by dan4domination
0
$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

0

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

Edited by dan4domination: n/a

0

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...

0

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


?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.