我正在编写PHP代码以将用户输入发送到数据库。 http://fwtest.ga/register.php是我的网址。每次我点击URL或检查JSONLint网站上的JSON数据时,我都会得到“mysqli_stmt_bind_param():”变量数与预备语句中的多个参数不匹配“这里是Mycode
<?php
$con = mysqli_connect("hostname", "username", "password", "dbname");
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$email = $_POST["email"];
$password = $_POST["password"];
$user_id = $_POST["user_id"];
$statement = mysqli_prepare($con, "INSERT INTO `user` (first_name, last_name, email, password) VALUES
('$first_name', '$last_name', '$email', '$password')");
mysqli_stmt_bind_param($statement, 'ssss', $first_name, $last_name, $email, $password);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
?>
答案 0 :(得分:0)
你正在注入参数并且你正在准备查询的同时,使用?
告诉mysql在哪里放置数据,从sql字符串中删除变量
$statement = mysqli_prepare($con, "INSERT INTO `user` (first_name, last_name, email, password) VALUES
(?, ?, ?, ?)");
答案 1 :(得分:0)
我在$ con之后声明了五个变量,并且只使用其中的四个mysqli_prepare函数。现在它正在运作。