我正在尝试使用 MySQLi 创建我的第一个准备好的语句,因为我知道我执行查询的方式对 SQL 注入是开放的。
我真的不明白其中的 bind_param 和 bind_result 部分。有人可以以最愚蠢的方式向我解释这一点。
这是我的有效查询。
$sql = "UPDATE formdata SET name = '$varName', email = '$varEmail', address = '$varAddress', city = '$varCity', state = '$varState', zip = '$varZip', submitDate = '$varDate' WHERE promoCode = '$varPromo'";
$mysqli->query($sql);
这是我对准备好的声明的尝试。
$query = "UPDATE formdata SET name = ?, email = ?, address = ?, city = ?, state = ?, zip = ?, submitDate = ? WHERE promoCode = '$varPromo'";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("s", $varName, $varName, $varEmail, $varAddress, $varCity, $varState, $varZip, $varDate);
$stmt->execute();
$stmt->bind_result($varName, $varName, $varEmail, $varAddress, $varCity, $varState, $varZip, $varDate);
$stmt->fetch();
header("location: index.php?success=1");
exit();