MYSQLi准备语句不起作用

时间:2017-09-21 10:02:52

标签: php mysql mysqli

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();

1 个答案:

答案 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();