Im creating a login php script that connects to a mysql db with a table called users containing a list of users. I am running into what looks like either an empty set or a mysql error.
I have included a connection error echo and a query die echo and the script is echoing the latter error that gives me the query string. I run this exact query in phpMyAdmin and get the result I expect (it returns the user).
Why is it dying?
$cxn was defined on the login page that calls this posts to this page
$pass = addslashes($_POST['password']);
$email = addslashes($_POST['username']);
$pw = md5($_POST['password']);
$query = "SELECT * FROM `users` WHERE (`user_email`='$email' AND `user_pass`='$pw')" ;
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($cxn,$query) or die(mysqli_error($cxn)."Query= ".$query);
Ive left the first version up. Here is the current incarnation which has the same result.
<?php
$email = ($_POST['username']);
$pw = md5($_POST['password']);
$query = "SELECT * FROM `users` WHERE (`user_email`='$email' AND `user_pass`='$pw')" ;
if (mysqli_connect_errno($cxn)){ //remove later
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} //to here
$result = mysqli_query($cxn,$query) or die(mysqli_error($cxn)."Query=".$query);
echo '<hr>';
echo $result;
while($row = mysql_fetch_array($result)){
echo $row['user_email'];
echo '<hr>';
echo $row['user_pass'];
echo '<hr>';
echo $row['user_fname'];
echo '<hr>';
}
?>