我完全迷失了,我無法通過 Stack Overflow 找到答案。我不確定我是否設定錯誤,但我收到警告:mysqli_stmt_bind_param():型別定義字串中的元素數與系結變數數不匹配。
我可以很好地更新資料庫,但我仍然收到警告錯誤。我以這種方式設定它以防止 SQL 注入。不確定我是否需要重組它的撰寫方式。任何幫助是極大的贊賞。
<?
$id = $_GET["id"];
$listdate = $_POST["list_date"];
$listprice = $_POST["list_price"];
$servername = "localhost";
$username = "***";
$password = "***";
$db = "u449450474_products";
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}
$sql = "UPDATE inventory SET list_date = '$listdate', list_price = '$listprice' WHERE product_id ='$id'";
$stmt = mysqli_stmt_init($conn);
if ( ! mysqli_stmt_prepare($stmt, $sql)){
die(mysqli_error($conn));
}
mysqli_stmt_bind_param($stmt, "ss",
$listdate,
$listprice
);
mysqli_stmt_execute($stmt);
if($conn->query($sql) === TRUE){
echo "Record Saved.";
echo "$sql";
} else {
echo "Error!";
}
$conn->close();
?>
uj5u.com熱心網友回復:
改變
$sql = "UPDATE inventory SET list_date = '$listdate', list_price = '$listprice' WHERE product_id ='$id'";
到
$sql = "UPDATE inventory SET list_date = ?, list_price = ? WHERE product_id = ?";
然后改變
mysqli_stmt_bind_param($stmt, "ss",
$listdate,
$listprice
);
到
mysqli_stmt_bind_param($stmt, "ssd",
$listdate,
$listprice,
$id
);
來源:https ://www.php.net/manual/en/mysqli-stmt.bind-param.php
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/480730.html
