输出ALways"记录错误"即使电子邮件或密码都正确

时间:2017-04-18 05:49:38

标签: javascript php

function db() {
    $con = new mysqli('localhost','root','','signupsystem') or die(  'eroor in connection'. mysqli_connect_error()); /* db connection */
    $query = "select * from adduser where email =? AND password =?";      
    $this->strm = $con->prepare($query); /* query prepare */
    if (!$this->strm) {    
        die($con->error);
    }           
    $this->strm->bind_param('ss', $this->email, $this->password);          
    $this->strm->execute();      /*execute query */ 
    if ($this->strm->affected_rows > 0) {                
        echo "successfully login";               
    } else {
        echo "error in logIn";
    }      
}

1 个答案:

答案 0 :(得分:0)

你正在做一个select语句,所以没有affected_row。在execute语句之后,您需要将结果绑定到变量,然后遍历查询结果。

    $stmt->bind_result($col1, $col2);

    /* fetch values */
    while ($stmt->fetch()) {
        echo $col1, $col2;
    }