我收到此错误:
Warning: mysqli_close(): Couldn't fetch mysqli in sendinvoice.php on line 54
这是我的代码:
<?php
include 'dbconfig.php';
ob_start();
$taxcb = $_POST['taxcb'];
$taxrate = $_POST['taxrate'];
$bcctocb = $_POST['bcctocb'];
$bcctotxt = $_POST['bcctotxt'];
$duedate = $_POST['duedate'];
$issuedate = $_POST['issuedate'];
$additemscb = $_POST['additemscb'];
$additemname = $_POST['additemname'];
$additemprice = $_POST['additemprice'];
$q = $_POST['rowid'];
$sql="SELECT * FROM clients WHERE id = '".$q."'";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result)) {
$to = $row[email];
$subject = "Invoice Test " . date('m/d/Y h:i:s a', time());
include 'invoice.html';
$message = ob_get_clean();
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <billing@example.com>' . "\r\n";
if ($bcctocb == "y"){
$headers .= 'BCC: ' . $bcctotxt . "\r\n";
}
mail($to,$subject,$message,$headers);
$sql = "UPDATE clients SET last_billed='" . date("Y-m-d H:i:s") . "' WHERE id=" . $q;
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
mysqli_close($conn);
?>
如果一切成功,我只希望它更新MySQL条目。我怀疑一次同时执行两个MySQL事情是错误的,是否有一种更有效的方式将它们组合在一起?
答案 0 :(得分:0)
缩进很难分辨,但是在某些情况下,您将两次关闭连接...
$conn->close();
}
mysqli_close($conn);
这两个都将关闭连接,因此第二个将失败。
可能更容易删除$conn->close();
,因为它将始终掉到第二个收盘价。
答案 1 :(得分:0)
我想您正在弄混mysqli
面向对象的版本和程序样式的版本,请坚持使用它,我敦促您使用OOP。
采用OOP风格:
/* do connection */
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* close connection */
$mysqli->close();
以程序样式:
/* do connection */
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* close connection */
mysqli_close($link);