I am trying to use PHP to do a simple API to update a certain column in a record in my database. However, I am stuck with Missing parameters error whenever I try something like http://localhost/set_is_open.php?open=0&shop_id=2
Here is my API:
<?php
header('Content-Type: application/json');
require_once 'db.php';
if(!isset($_GET["open"]) || empty(trim($_GET["open"])) || !isset($_GET["shop_id"]) || empty(trim($_GET["shop_id"])))
die(json_encode(array("error" => "Missing request paramters.")));
$isOpen = trim($_GET["open"]);
$shop_id = trim($_GET["shop_id"]);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'UPDATE shops
SET is_open = isOpen
WHERE shop_id = shop_id';
mysql_select_db('shops');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
?>
I doubt that there is something wrong I am doing maybe in the syntax, but I couldn't figure it out. I followed this tutorial here