dqkkrt8860 2018-11-20 15:27
浏览 110
已采纳

绑定变量的数量与php和android中预准备语句中的字段数不匹配

I tried running this script through Android, but the response is this;

Number of bind variables doesn't match number of fields in prepared statement

I do not know what this means, but my script was just supposed to log the person in if their input info is correct. Then, grab a string from the db and return it back to android. Can someone explain what im doing wrong? And what that error even means?

My script looks like this;

<?php
    $db_host = 'localhost:3306';
    $db_user = 'root';
    $db_pass = '';
    $db_name = 'test';

    $con = mysqli_connect($db_host,'user',$db_pass,$db_name);
    $username = $_POST["username"];
    $password = $_POST["password"];
    $statement = mysqli_prepare($con, "SELECT * FROM cresidentials WHERE username = ? AND password = ?");
    mysqli_stmt_bind_param($statement,"ss",$usermame,$password);
    mysqli_stmt_execute($statement);

    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement,$username,$password,$isAdmin);
    echo $isAdmin;
    ?>
  • 写回答

2条回答 默认 最新

  • dongmi6102 2018-11-20 15:52
    关注

    OP's table of course also has an id column (which I discovered after he share a screenshot with me through chat), you also need to bind it.

    mysqli_stmt_bind_result($statement, $user_id, $username, $password, $isAdmin);

    Instead of:

    mysqli_stmt_bind_result($statement,$username,$password,$isAdmin);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?