Note that there are some explanatory texts on larger screens.

plurals
  1. POin_array function returning true always
    text
    copied!<p>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:</p> <pre><code>&lt;?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); ?&gt; </code></pre> <p>However, it is consistently placing a booking even if these conditions aren't met. Why is this the case? Thanks, Dayne.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload