Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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 mysqli stmt绑定结果未获取值_Php_Mysql - Fatal编程技术网

PHP mysqli stmt绑定结果未获取值

PHP mysqli stmt绑定结果未获取值,php,mysql,Php,Mysql,有人能告诉我这个代码有什么问题吗?几个小时以来,我一直试图从数据库中获取值,结果总是空的。。除了用户名和密码 <?php $con = mysqli_connect("aaaaa", "bbbbb", "cccccc", "ddddd"); $email = $_POST["email"]; $password = $_POST["password"]; $statement = mysqli_prepare($con, "SELECT * FROM table WHERE email

有人能告诉我这个代码有什么问题吗?几个小时以来,我一直试图从数据库中获取值,结果总是空的。。除了用户名和密码

<?php
$con = mysqli_connect("aaaaa", "bbbbb", "cccccc", "ddddd");

$email = $_POST["email"];
$password = $_POST["password"];

$statement = mysqli_prepare($con, "SELECT * FROM table WHERE email = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $email, $password);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $id, $full_name, $email, $password, $distance, $average_rating, $home_address, $work_address);

$response = array();
$response["success"] = false;

while(mysqli_stmt_fetch($statement)){
    $response["success"] = true;
    $response["full_name"] = $full_name;
    $response["email"] = $email;
    $response["password"] = $password;
    $response["distance"] = $distance;
    $response["average_rating"] = $average_rating;
    $response["home_address"] = $home_address;
    $response["work_address"] = $work_address;
}

echo json_encode($response);
?>

好的,我已经用下面的代码解决了我的问题。我不知道以前的代码有什么问题。如果有人碰巧知道这个问题的解决办法,请在评论中回答,我很好奇。注:此代码仅用于测试建议

<?php
$con = mysqli_connect("aaa", "bbb", "ccc", "ddd");

$email = $_POST["email"];
$password = $_POST["password"];

$sql = "SELECT * FROM table";
$result = mysqli_query($con, $sql);


$response = array();
$response["success"] = false;

while($row = mysqli_fetch_assoc($result)){
    if($row["email"]==$email && $row["password"] == $password){
        $response["success"] = true;
        $response["full_name"] = $row["full_name"];
        $response["email"] = $row["email"];
        $response["password"] = $row["password"];
        $response["distance"] = $row["distance"];
        $response["average_rating"] = $row["average_rating"];
        $response["home_address"] = $row["home_address"];
        $response["work_address"] = $row["work_address"];
        break;
    }
}

echo json_encode($response);
?>

好的,我已经用下面的代码解决了我的问题。我不知道以前的代码有什么问题。如果有人碰巧知道这个问题的解决办法,请在评论中回答,我很好奇。注:此代码仅用于测试建议

<?php
$con = mysqli_connect("aaa", "bbb", "ccc", "ddd");

$email = $_POST["email"];
$password = $_POST["password"];

$sql = "SELECT * FROM table";
$result = mysqli_query($con, $sql);


$response = array();
$response["success"] = false;

while($row = mysqli_fetch_assoc($result)){
    if($row["email"]==$email && $row["password"] == $password){
        $response["success"] = true;
        $response["full_name"] = $row["full_name"];
        $response["email"] = $row["email"];
        $response["password"] = $row["password"];
        $response["distance"] = $row["distance"];
        $response["average_rating"] = $row["average_rating"];
        $response["home_address"] = $row["home_address"];
        $response["work_address"] = $row["work_address"];
        break;
    }
}

echo json_encode($response);
?>


我建议在
while(mysqli_stmt_fetch($statement){echo…}
中对整个内容进行一次
echo(只是为了看看发生了什么)。我不确定,但如果我用
$response[“full_name”]=$full_name;
更改
$response[“full_name”]=“some text”
,我在json响应中获得some text值……这意味着当我将
$response
值传递给
$response[“full_name”]时,该值为空
,对吗?我不知道如何在while中进行回音,如果我尝试,我会在json响应中得到
成功:false
。尝试查询特定字段而不是*@RST,我已经尝试过了,没有任何变化。我建议
回音
while(mysqli_stmt_fetch($statement){echo…}
一次(只是想看看发生了什么)。我不确定,但如果我用
$response[“full\u name”]=$full\u name;
更改
$response[“full\u name”]=”一些文本,我认为您正在覆盖
$response[]中的值“
,我在json响应中获得了一些文本值……这意味着当我将
$response
值传递给
$response[“全名”]时,
$response
值为空”
,对吗?我不知道在这段时间内如何回音,如果我尝试回音,我会在json响应中得到
success:false
。尝试查询特定字段而不是*@RST,我已经尝试过了,没有任何更改。。