1
我是PHP的新手,我試圖讓一個準備好的語句工作。它爲我在大學的最後一年的項目,我記得讀過準備好的聲明是很好的做法,也適用於SQL注入。但是下面的代碼給我一個Server 500錯誤。準備語句使用bindValue不起作用
<?php
$email = "[email protected]";
$hash = "somerandomhashedpassword";
$db = new mysqli("localhost", "root", "1234", "UEAnetwork");
$sql = "INSERT INTO Students (Email, Password) VALUES (?,?)";
$stmt = $db->prepare($sql);
$stmt->bindValue(1, $email);
$stmt->bindValue(2, $hash);
if ($stmt->execute()) {
echo "You have registered!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
}
?>
如果我運行下面再行插入,所以我敢肯定我連接到數據庫正常。我是用bindValue
不正確?我已經看到它在網上的很多教程中都以這種方式使用,但我一定在做錯事。
我想你混淆PDO的語法與庫MySQLi - PDO使用bindValue,而mysqli的使用bind_param - http://php.net/manual/en /mysqli-stmt.bind-param.php,它的工作方式稍有不同。 – andrewsi
使用合適的IDE可以輕鬆解決它。 –