I am still new in the PHP and MySQL. I just started to learn MySQLi before few days and I met this problem. This page is named login.php. The problem is that the query return 0 num rows. When I run the query in phpmyadmin it show this message and 1 row.
Showing rows 0 - 0 (1 total, Query took 0.0010 sec)
Image:
Here is my code:
<?php
session_start();
require 'config.php';
$username = $_POST['username'];
$password = $_POST['password'];
$salt = 'qwerty';
$pass_prepare = md5($salt).sha1($password);
if ($_SERVER['REQUEST_METHOD'] != "POST") {
header('Location: index.php');
}
if (isset($username) && isset($pass_prepare)) {
$stmt = mysqli_prepare($db_con, "SELECT user_id, username, password, rank, last_activity FROM imes_users WHERE username=? AND password=? LIMIT 1");
mysqli_stmt_bind_param($stmt, "ss", $username, $pass_prepare);
mysqli_execute($stmt);
mysqli_stmt_bind_result($stmt, $user_id, $username1, $password1, $rank, $last_activity);
mysqli_stmt_fetch($stmt);
echo mysqli_num_rows($stmt);
} else {
echo 'error';
}
Could you help me to fix this issue?