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条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站