php - mysqli prepared statement doesn't seem to work -
i have following code:
<?php if(!empty($_post)){ $db = new mysqli('localhost', 'root', '', 'verif1'); $password = $_post['pass']; $username = $_post['user']; $table = "admins"; $password = hash("sha256", $password); $statement = $db->prepare("select count(*) {$table} username = ? , password = ?"); $statement->bind_param("ss", $username, $password); $statement->execute(); $statement->bind_result($numrows); if($numrows == 1){ echo "yeah correct!<br>"; }else{ echo "no :(<br>"; } } ?> <form action="" method="post"> <input type="textbox" name="user"> <br> <input type="password" name="pass"> <br> <input type="submit"> </form>
i'm sure correct (no error throwing, nothing) doesn't work! tried print_r() see objected has returned , this: after execute() this:
print_r($statement); die();
and gives me this:
mysqli_stmt object ( [affected_rows] => -1 [insert_id] => 0 [num_rows] => 0 [param_count] => 2 [field_count] => 1 [errno] => 0 [error] => [error_list] => array ( ) [sqlstate] => 00000 [id] => 1 )
if check documentation - http://www.php.net/manual/en/mysqli-stmt.bind-result.php see you've forgotten fetch()
data
$statement->fetch();
Comments
Post a Comment