MySQLi,插入预备语句错误
$conn = new mysqli($servername, $username, $password, $dbname);
$stmt = $conn->prepare("INSERT INTO users (firstname, lastname, email,password) VALUES (?, ?, ? ,?)");
$stmt->bind_param("ssss",$firstname,$lastname,$email,$pass); //<-- return 500 status
// // set parameters and execute
$firstname = "John";
$lastname = "Doe";
$email = "john@example.com";
$pass = "Doe";
$stmt->execute();
答案 0 :(得分:0)
我喜欢使用占位符,试一试!
$sql ="INSERT INTO users (firstname, lastname, email,password)
VALUES (:first, :last, :email , :pass)";
$stmt = $conn->prepare($sql);
$stmt->bindValue('first', $firstName);
$stmt->bindValue('last', $lastName);
$stmt->bindValue('email', $email);
$stmt->bindValue('pass', $password);
$stmt->execute();