Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 变量数量不为';t与中已准备语句中的参数数不匹配_Php - Fatal编程技术网

Php 变量数量不为';t与中已准备语句中的参数数不匹配

Php 变量数量不为';t与中已准备语句中的参数数不匹配,php,Php,我正在编写PHP代码以将用户输入发送到数据库。这是我的网址。每次单击URL或检查JSONLint网站中的JSON数据时,我都会得到“mysqli_stmt_bind_param():“变量数量与准备语句中的参数数量不匹配”这是Mycode <?php $con = mysqli_connect("hostname", "username", "password", "dbname"); $first_name = $_POST["first_name"]; $last_name = $_

我正在编写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);
?>

您正在注入参数,同时准备查询,请使用
告诉mysql将数据放置在何处,从sql字符串中删除变量

$statement = mysqli_prepare($con, "INSERT INTO `user` (first_name, last_name, email, password) VALUES 
(?, ?, ?, ?)");

我在$con后声明了五个变量,并且只使用了其中四个mysqli_prepare函数。现在它开始工作了。

快速编辑您的问题,您共享了敏感信息,这可能会对您造成一些伤害,谢谢!是的,我尝试过,我声明了五个变量,只使用了四个。现在它已修复。