duanba8173 2016-07-18 05:21
浏览 17

PHP - 我的SQL查询不接受多个php变量[重复]

below is mysql query, the problem is the query only works as long as there is only one php variable such as

 Select * From student where Account = ".$username."

but if I change the code to be as below, I got the error

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given.

What might be the problem here, please help me.

    $result = $con->query("SELECT * FROM '.$role.' WHERE Account = '.$username.' AND password = '.$password.' AND IsApproved = '.$approval.'");

    if(mysqli_num_rows($result) == 1) {
      $_SESSION['username'] = $username;
      header('Location: include/test.php');
    }
    else {
      echo "Account is invalid";
    }
  }

EDIT : PROBLEM SOLVED - Answer by Dhaval Dave

 $result = $con->query("SELECT * FROM {$role} WHERE Account = '{$username}' AND password = '{$password}' AND IsApproved = '{$approval}'");

Thanks alot to everyone for helping me all the suggestion, I appreciated what you guys did to me. Thanks alot x1000

</div>
  • 写回答

4条回答 默认 最新

  • douweida2878 2016-07-18 05:24
    关注
    $result = $con->query("SELECT * FROM ".$role." WHERE Account = ".$username." AND password = ".$password." AND IsApproved = ".$approval.");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人