我在处理这段代码时遇到了问题。基本上,当页面打开时,会自动将条目输入到表中并显示唯一 ID 'CustomerRequestID'。输入其余详细信息后,用户可以按“提交”,这将使用其他详细信息更新条目。但是,当用户按下提交时,它实际上会在执行提交代码之前再次执行初始代码,从而创建一个附加条目。例如,如果生成的 ID 为 59,则用户单击“提交”,代码创建另一个 ID 为 60 的条目,并将更新应用于该条目而不是 59。我怎样才能使它不生成第二个条目,以及而是只更新初始条目?
<?php
include_once ("resource/db_conn.php");
$id = $_GET['ID'];
$query = "SELECT * FROM `customer` WHERE `CustomerId`='$id'";
$retrieval = mysql_query($query);
$rowCustomer = mysql_fetch_array($retrieval);
$customerID = $rowCustomer['CustomerID'];
$customerName = $rowCustomer['CustomerName'];
// creates the new supplier ID
$sql = "INSERT INTO `customer_requests`(`CustomerRequestID`, `Title`, `Description`, `RFQDate`, `Q2CDate`, `QuantityRequested`, `GST`,`NetCost`, `Markup`,`NetSellPrice`, `GrossSellPrice`, `fkCustomerID` , `Status`) VALUES ('','','','','','','','','','','','$customerID','')";
$result = mysql_query($sql);
$addedEntry = "SELECT * FROM customer_requests ORDER BY CustomerRequestID DESC LIMIT 1";
$retrieved = mysql_query($addedEntry);
$row = mysql_fetch_array($retrieved);
if(isset($_POST['submit'])) {
$cRID = $row['CustomerRequestID'];
$title = $_POST['title'];
$description = $_POST['description'];
// validation goes here
$insertSQL="UPDATE `customer_requests` SET `Title` = '$title', `Description` = '$description' WHERE `CustomerRequestID` ='$cRID'";
$updateSQL = mysql_query($insertSQL);
?>
<script>window.close();</script>
<?php
}
?>