I’m constructing a webpage to submit camera bookings to a MYSQL database. This webpage has a html frontend that forwards it to the following PHP page, which then submits that information to the MYSQL
Currently the client wishes for there to be no way of making duplicate bookings of the Cameras. To fulfill this, I have constructed the following PHP page, which checks if the chosen camera in the html frontend ($_POST[camera]) is the same as anything in the $result_array array. The code is as follows:
<?php
$con = mysql_connect("****","*****","*******");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("****", $con);
$query = "SELECT Camera FROM T_Bookings";
$result = mysql_query($query) or die ("no query");
$result_array = array();
while($row = mysql_fetch_array($result)) {
$result_array[] = $row;
}
$fixed_array = array_keys($result_array);
if (in_array($_POST[camera],$result_array)){
$x = 1;
$y = 2;
}
if($x + $y == 3){
echo "Camera already booked!";
}
else {
mysql_query("INSERT INTO T_Bookings (F_Name, L_Name, Camera, Bag, Cable, Tripod, MemoryCard, Date, Authorised)
VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[camera]','$_POST[bag]','$_POST[cable]','$_POST[tripod]','$_POST[memory]','$_POST[date]',)");
echo "1 record added";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
mysql_close($con);
?>
However, it is consistently placing a booking even if these conditions aren’t met. Why is this the case?
Thanks,
Dayne.
mysql_fetch_array($result) returns an array like
So change the line below to read