我想更新表中只有CHARGES的值。我的错误是:
注意:第4行的C:\ xampp \ htdocs \ VCCDMStry \ pages \ save_receipt.php中的未定义索引:id
注意:未定义的索引:第5行的C:\ xampp \ htdocs \ VCCDMStry \ pages \ save_receipt.php收费
致命错误:未捕获的异常' PDOException' with message' SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以便在#< WHERE id = NULL' WHERE id = NULL'附近使用正确的语法。在第1行'在C:\ xampp \ htdocs \ VCCDMStry \ pages \ save_receipt.php:8堆栈跟踪:#0 C:\ xampp \ htdocs \ VCCDMStry \ pages \ save_receipt.php(8):PDOStatement-> execute(Array)#1 {main}在第8行的C:\ xampp \ htdocs \ VCCDMStry \ pages \ save_receipt.php中抛出
这是我的fetch代码:
<?php
$sql = "SELECT * FROM tenant
LEFT JOIN stall ON stall.stall_id = tenant.stall_id
LEFT JOIN rent ON rent.tenant_id = tenant.tenant_id
LEFT JOIN receipt ON receipt.tenant_id = tenant.tenant_id
LEFT JOIN rate ON rate.rate_id = tenant.rate_id
WHERE rent.rent_status = ? AND rate.rate_id = ?
";
$query = $conn->prepare($sql);
$query->execute(array(1,1));
$fetch = $query->fetchAll();
foreach ($fetch as $key => $value) { ?>
<tr>
<td>
<?=$value['tenant_fname']." ".$value['tenant_mname']." ".$value['tenant_lname'];?>
</td>
<td>
<?=$value['stall_number'];?>
</td>
<td>
<?=$value['charges'];?>
</td>
<td class = "center" style = "text-align:center;">
<a href = "#receipt<?php echo $value['tenant_id'];?>" data-toggle="modal" class="btn btn-outline btn-xs btn-primary"> Make Receipt
</a>
</td>
</tr>
<?php include 'receipt_modal.php';?>
<?php }?>
以下是我更新的代码:
<?php
include 'dbcon.php';
$receipt_id = $_POST['id'];
$charges = $_POST['charges'];
$query = $conn->prepare("UPDATE receipt SET charges = ? , WHERE id = ? ");
$query->execute(array($charges,$receipt_id));
header ('location:elecbills.php');
?>
模态代码:
<div class="form-group">
<input type = "hidden" class="form-control" name= "id" value = "<?php echo $value['tenant_id'];?>">
<label class="col-sm-4 control-label">PRESENT </label>: <input class = "custom-input" id="charges" name="charges"></input>
</div>
答案 0 :(得分:0)
引发致命错误导致您在“之前”处有逗号错误。
UPDATE receipt SET charges = ? , WHERE id = ?