我一直在尝试学习在PHP中使用准备好的语句。我不知道为什么我的准备每次都会失败。我有一张小桌子,上面有三列。该表是Test
。列是
A_ID, FirstName, LastName
A_ID id an auto increment
。
$connection = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($connection->connect_errno) {
echo "The prepared statement failed to connect ERROR: (" . $connection- >connect_errno . ") " . $connection->connect_error;
}
$FirstName = $_GET["FirstName"];
$LastName = $_GET["LastName"];
echo $FirstName . ", " . $LastName . "<hr>";
if (!($stmt = $connection -> prepare("INSERT INTO Test (FirstName, LastName)
VALUES (?,?)"))); {
echo "Prepare failed: (" . $connection->errno . ") " . $connection->error;
echo "<hr>";
//$stmt->debugDumpParams();
}
var_dump($stmt);
echo "<hr>";
if (!$stmt->bind_param ("ss", $FirstName, $LastName)) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
echo "return : " . $stmt->affected_rows;
$stmt->close();
$connection->close();
?>
您在这里有一个语法错误,与以下内容无关;
:
if (!($stmt = $connection -> prepare("INSERT INTO Test (FirstName, LastName)
VALUES (?,?)"))); { //rest of the code
应该是这样的:
if (!($stmt = $connection -> prepare("INSERT INTO Test (FirstName, LastName)
VALUES (?,?)"))) { //rest of the code
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句