Hi I am trying to update my mysql database using php. I can update it perfectly with the following:
<?php
$conn = mysqli_connect("localhost", "root", "", "logintest");
if(!$conn){
die("Connection failed: ".mysqli_connect_error());
}
?>
<?php
$sql = "UPDATE user SET bot = '1' WHERE id = 9";
if($conn -> query ($sql) === TRUE){
echo "record updated successfully";
}else{
echo "Error updating record" . $conn -> error;
}
$conn -> close ();
?>
But before I update the above bot column to 1, I want to check and see if it is 0, as it can only be 0 or 1. To do this I done the following (see below) but it isn't working, Is it possible and or Is there a different way of doing it? All help is appreciated thanks!!
$sql = "SELECT bot FROM user"; // bot is the column in the table which should be 0 or 1
if( $sql == '0') { //if its 0 i can update it
echo 'here'; //if i get here i will update using code above
}
if (x === TRUE)in your code. Just test usingif (x)most of the time.