这是我的代码。我想更新我的数据库值。但它不起作用。 我想更新状态从(待定)到(借用)AND从(returnP)更新到(返回)。
这是代码:
if(isset($_GET['gate']))
{
extract($_GET);
$timestamp=date("d/m/y h:i:sA",time());
$sql = "SELECT *FROM rent_record WHERE pass_open='$gate'";
$result = $conn->query($sql);
$row = mysqli_fetch_array($result);
$name = $row["ID"];
$status = $row["status"];
if (($gate==$name) AND ( $status=='pending'))
{
$sql = "UPDATE rent_record SET status='borrowed' WHERE ID='$name';";
if ($conn->query($sql) === TRUE) header('Location: '.BASE_URL.'/keypad');
else echo "Error: " . $sql . "<br>" . $conn->error;
$sql = "UPDATE rent_record SET time_taken='$timestamp' WHERE ID='$name';";
if ($conn->query($sql) === TRUE) header('Location: '.BASE_URL.'/keypad');
else echo "Error: " . $sql . "<br>" . $conn->error;
}
else if (($gate==$name) AND ( $status=='returnP'))
{
$sql = "UPDATE rent_record SET status='returned' WHERE ID='$name';";
if ($conn->query($sql) === TRUE) header('Location: '.BASE_URL.'/keypad');
else echo "Error: " . $sql . "<br>" . $conn->error;
$sql = "UPDATE rent_record SET time_return='$timestamp' WHERE ID='$name';";
if ($conn->query($sql) === TRUE) header('Location: '.BASE_URL.'/keypad');
else echo "Error: " . $sql . "<br>" . $conn->error;
}
}
else
{
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$sql = "SELECT pass_open, pass_closed FROM rent_record WHERE status='pending' OR status='returnP'";
$result = $conn->query($sql);
$outp = '[';
while($rs = $result->fetch_array(MYSQLI_ASSOC))
{
if ($outp != '[') {$outp .= ',';}
$outp .= '{"ID":"' . $rs['ID'] . '",';
$outp .= '"password":"' . $rs['pass_open'] . '"}';
$outp .= '"password":"' . $rs['pass_closed'] . '"}';
}
$outp .=']';
echo($outp);
}
希望有人可以帮助我。先谢谢你。