I am relatively new to PHP and am working on my first project. I am creating a website that our dept. can use to check vehicles in and out. They start at the vehicle list page and choose a vehicle then click on Check out which processes the following code.
The $checkavail selects the Availability field in the database which is either 'Yes' or the name of the user. If it's Yes it should run the code, otherwise echo that its unavailable. The problem is that it keeps echoing unavailable even though the IF statement should be resulting in true.
If I need any clarifications please let me know.
Thanks.
<?php
$vehicle=$_POST['chosenvehicle'];
$name=$_SESSION['myusername'];
$Checkout = date("m/d/y : h:i:A", time());
$DBConnect = @mysqli_connect("localhost", "", "*")
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "<p>";
@mysqli_select_db($DBConnect, "cityvehicle")
Or die("<p>Unable to select the database.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
$kronosNumber= "(SELECT kronosNumber FROM member WHERE loginName='$name' )";
$QueryResult = @mysqli_query($DBConnect, $kronosNumber)
Or die("<p>Unable to execute the query1.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>";
$checkAvail= "(SELECT availability FROM vehicles WHERE Sec_ID='$vehicle')";
$QueryResult1 = @mysqli_query($DBConnect, $checkAvail)
Or die("<p>Unable to execute the query2.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>";
if ($QueryResult1 == 'Yes') {
$SQLstring= "INSERT INTO logsheet VALUES('$name', '$vehicle', $kronosNumber, '$Checkout', '')";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query3.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>";
$SQLstring2= "UPDATE vehicles SET availability='$name' WHERE Sec_ID='$vehicle'";
$QueryResult = @mysqli_query($DBConnect, $SQLstring2)
Or die("<p>Unable to execute the query4.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>";
$to = "itvehicles@elpasotexas.gov";
$message = "$name has just checked out vehicle $vehicle.";
$from = "Vehicle log";
mail($to,$from,$message);
echo "<h3>You have checked out vehicle $vehicle.</h3>";
}
else {
echo "That vehicle is unavailable."; }
?>