0
我正在創建註冊表單,並且在將數據插入數據庫時使用了PHP綁定參數。PHP bind_param錯誤:在數據庫中插入問號('?')而不是實際值
$fnameclean = mysqli_real_escape_string($mysqli_conn, $_POST['first_name']);
$passwordclean = mysqli_real_escape_string($mysqli_conn, hash("sha512", $_POST['password']));
$lnameclean = mysqli_real_escape_string($mysqli_conn, $_POST['last_name']);
$emailclean= mysqli_real_escape_string($mysqli_conn, $_POST['email']);
$stmt = $mysqli_conn->prepare("INSERT INTO user (firstname, surname, email, password) VALUES ('?', '?', '?', '?')");
$stmt->bind_param("ssss", $fnameclean, $lnameclean, $emailclean, $passwordclean);
$stmt->execute();
$stmt->close();
當我按下提交按鈕,我可以在我的數據庫看到在田裏問號:名字,姓氏,電子郵件地址和密碼。
然而,當我嘗試沒有它工作完全正常
代碼綁定參數信息添加到數據庫中:
$query1 = "INSERT INTO user (firstname, surname, email, password) VALUES ('$fnameclean', '$lnameclean', '$emailclean', '$passwordclean')";
$mysqli_conn->query($query1);
我在做什麼錯在這裏?
''?''不是一個綁定參數,它是一個字符串文字。 – Neil
我發現了錯誤,它應該像VALUES(?,?,?,?)而不是VALUES('?','?','?','?') – user5455438