My SQL query is not working. Below is my code and note that in that table query worked fine and gives output. But in PHP by using mysqli_num_rows()
, mysqli_fetch_assoc()
and mysqli_fetch_array()
all doesn’t works for me.
My DB connection is :
$conn = mysqli_connect($servername, $username, $password, $db);
Note : My DB Connectivity is fine.
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$query = mysqli_query($conn, "SELECT * FROM `admin` WHERE `username`='$username'");
This query results true in PHPMyAdmin and returns false in PHP with the above functions. Can anyone answer is I made a mistake?
And I am tried that query to execute in following methods :
$row = mysqli_fetch_assoc(); // Results No Data
$data = mysqli_fetch_array($query); // Results No Data
$num = mysqli_num_rows($query); // Results 0 Data
2
Answers
you may execute the query before use it :
You mast to run
mysqli_query
function for receive result from DB:PHP MySQL sandbox here