此代码已经工作了一段时间,但突然之间没有任何改变。代码的第一部分是检查用户的凭据是否正确。如果是,则将表单中输入的数据提交给mysql,并发送电子邮件通知。这是代码:
<?php
if(isset($_POST['insert'])){
$hostname = "localhost";
$username = "root";
$password = "";
$databaseName = "change_management";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$user = $_POST['user'];
$passcode = $_POST['passcode'];
$sql = "SELECT * FROM admin WHERE username = '" . $user . "' and passcode ='".md5($passcode)."'";
$result = mysqli_query($connect,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count ==0) {
echo "
<font color=red><strong>Authentication failed - Invalid credentials</font></strong><br><br>";
}
else {
$change_id = $_POST['change_id'];
$approval_disposition = $_POST['approval_disposition'];
$approval_reason = $_POST['approval_reason'];
$approval_impact = $_POST['approval_impact'];
$user = $_POST['user'];
$approval_date = date('Y/m/d');
$approval_expiry_date = date('Y/m/d', strtotime('+2 weeks'));
$query = "UPDATE change_request_tbl SET approval_disposition='$approval_disposition', approval_reason='$approval_reason', approval_impact='$approval_impact', approval_name='$user', approval_date='$approval_date', approval_expiry_date='$approval_expiry_date' WHERE change_id='$change_id'";
$query = "SELECT `change_requestor` FROM `change_request_tbl` WHERE `change_id` = $change_id";
$result1 = mysqli_query($connect,$query);
while ($row = mysqli_fetch_array($result1))
$to = "******, ****, ****, *****, $row[change_requestor]";
$subject = "New Change Acceptance Board (CAB) Approval";
$message = "
<html>
<head>
<style>
body {font-family: Calibri;}
body {font-style: italic;}
.table {
background-color: white;
}
</style>
<title>Change Acceptance Board Approval</title>
</head>
<body>
<p>A new Change Acceptance Board (CAB) Approval has been submitted:</p>
<table border=4 bordercolor=black class=table>
<tr>
<th>Change ID:</th>
<th>Disposition:</th>
<th>Reason for Rejection or Exceptions:</th>
<th>Impact (By CAB):</th>
<th>Approved/Rejected by:</th>
<th>Date Approved:</th>
<th>Approval Expiry Date*:</th>
</tr>
<tr>
<td>$change_id</td>
<td>$approval_disposition</td>
<td>$approval_reason</td>
<td>$approval_impact</td>
<td>$user</td>
<td>$approval_date</td>
<td>$approval_expiry_date</td>
</tr>
</table>
<p>*This change must be completed by the Expiry Date. If this is not achieved a second CAB Request must be raised referencing this Change ID.</p>
</body>
</html>";
$headers = "MIME-Version:1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .='From: <******>' . "\r\n";
mail($to,$subject,$message,$headers);
echo "
Your CAB Approval Form has been submitted. You will receive an email confirmation shortly.<br><br>";
}
}
?>
我没有收到任何错误,但我收到的电子邮件中包含正确的信息。此问题仅与更新查询有关。有什么想法突然停止了吗?
答案 0 :(得分:2)
您宣布$query
两次,因此请使用以下UPDATE
覆盖SELECT
查询。
答案 1 :(得分:1)
$query = "UPDATE change_request_tbl SET approval_disposition='$approval_disposition', approval_reason='$approval_reason', approval_impact='$approval_impact', approval_name='$user', approval_date='$approval_date', approval_expiry_date='$approval_expiry_date' WHERE change_id='$change_id'";
$result = mysqli_query($connect,$query);
$query = "SELECT `change_requestor` FROM `change_request_tbl` WHERE `change_id` = $change_id";
$result1 = mysqli_query($connect,$query);
在问题中重写了可查询的SQL查询
答案 2 :(得分:0)
我相信你的问题在于:
$query = "UPDATE change_request_tbl SET approval_disposition='$approval_disposition', approval_reason='$approval_reason', approval_impact='$approval_impact', approval_name='$user', approval_date='$approval_date', approval_expiry_date='$approval_expiry_date' WHERE change_id='$change_id'";
$query = "SELECT `change_requestor` FROM `change_request_tbl` WHERE `change_id` = $change_id";
$result1 = mysqli_query($connect,$query);
UPDATE $查询被后续的SELECT $查询覆盖,因此它只是选择数据但不会事先更新。