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

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值