douwan4993 2013-10-29 15:58
浏览 78

通过bind_param插入值时,使用mysqli登录会出错

so I want to make a simple login and it works but when I use bind_param, it always shows 0 rows.

Here is the code:

session_start();
include("config.php");
$email = $_POST['email'];
$password = $_POST['password'];

if ($sql = $mysqli->prepare("SELECT email FROM user WHERE email='?' AND password LIKE SHA1('?')")) {

    $sql->bind_param('ss',$email, $password);

    $sql->execute();

    $sql->store_result();

    $num = $sql->num_rows;

    $sql->close();

    if($num>0){
        echo "true";
    }else{
        echo "false";
    }
}

I confirmed that I receive both email and password fields but the query only gets results when I manually enter them instead of "?" and removing bind_param.

I know that it is simple, but I can't figure out what's wrong.

Thanks in advance.

  • 写回答

4条回答 默认 最新

  • douzhao9608 2013-10-29 16:03
    关注

    remove quotes from ? it'll not be working with quotes... You can check some examples here, http://php.net/manual/en/mysqli-stmt.bind-param.php

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用