这个问题在这里已经有了答案:
mysqli_query():无法获取mysqli错误(1个答案)
9个月前关门了。
我得到这个错误:
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是错误的,有没有更有效的方法来组合它们?
2条答案
按热度按时间hfyxw5xn1#
我猜你在搞砸
mysqli
面向对象的版本和过程风格的版本,只要坚持一个,我敦促你使用面向对象。在oop样式中:
在程序样式中:
见exampleshttp://php.net/manual/en/mysqli.affected-rows.php
pieyvz9o2#
用缩进很难判断,但在某些情况下,你会关闭连接两次。。。
这两个都将关闭连接,因此第二个将失败。可能更容易移除
$conn->close();
因为它总是会跌到第二关。