嗨大家我有一个监控系统,它可以监控进来的租户并在一个摊位出来。如果您是第一次在该摊位上插入租户,INSERT可正常工作,但在该租户未租赁并使该租户状态无效后,他/她离开的那个摊位现在可用。之后,我不能在那个摊位上插入租户。
这是我的代码:
<?php
include ('dbcon.php');
if (isset($_POST['add'])){
$tenant_fname = $_POST['tenant_fname'];
$tenant_mname = $_POST['tenant_mname'];
$tenant_lname = $_POST['tenant_lname'];
$tenant_address = $_POST['tenant_address'];
$tenant_contact = $_POST['tenant_contact'];
$stall_id = $_POST['stall_id'];
$stall_name = $_POST['stall_name'];
$stall_category = $_POST['stall_category'];
$q1 = $conn->prepare("SELECT * FROM tenant WHERE stall_id = ? ");
$q1->execute(array($stall_id));
$c = $q1->rowCount();
if (!$stall_id){
header('location:pages/tenants.php');
}else{
if ($c > 0){
header('location:pages/tenants.php');
}else{
$add = $conn->prepare("INSERT INTO tenant (rate_id,tenant_fname, tenant_mname, tenant_lname, tenant_address, tenant_contact, stall_id, stall_name, stall_category)
VALUES (?,?,?,?,?,?,?,?,?) ");
$add->execute(array(1,$tenant_fname,$tenant_mname,$tenant_lname,$tenant_address,$tenant_contact,$stall_id,$stall_name,$stall_category));
$count = $add->rowCount();
$tenant_id = $conn->lastInsertId();
$date_today = date('F d, Y');
if ($count > 0){
$add1 = $conn->prepare("INSERT INTO tenant_status (tenant_id, date_started, date_ended, tenant_status) VALUES(?,?,?,?) ");
$add1->execute(array($tenant_id,$date_today,0,1));
$add2 = $conn->prepare("INSERT INTO rent (tenant_id,stall_id,rent_status) VALUES (?,?,?)");
$add2->execute(array($tenant_id,$stall_id,1));
$add3 = $conn->prepare("INSERT INTO receipt(tenant_id) VALUES (?)");
$add3->execute(array($tenant_id));
}
header('location:pages/tenants.php');
}
}
}
?>
BTW,值0表示租户无效,1表示有效。