I am coding a function to update the "status" attribute in the "users" table.
A status of 1 will mean that the user is online while a status of 0 will mean that the user is offline.
I trying coding a PHP file to set the status to 1 whenever a user logs in.
No matter what, the PHP call returns a 0 telling me that the update query failed to execute. Checked the codes multiple times but I can't seem to locate any errors.
Can somebody help me out?
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
error_reporting(E_ERROR);
try{
$conn = new mysqli("127.0.0.1", "root", "root", "classads");
$userID = $_GET['userid'];
$query = "update users set status = 1 where userid = " . $userID;
$result = $conn->query($query);
if (!$result){
$json_out = "[" . json_encode(array("result"=>0)) . "]";
}
else {
$json_out = "[" . json_encode(array("result"=>1)) . "]";
}
echo $json_out;
$conn->close();
}
catch(Exception $e) {
$json_out = "[".json_encode(array("result"=>0))."]";
echo $json_out;
}
?>
enter image description here
useridcolumn?useridcolumn of typeVARCHAR?