PDA

View Full Version : query trouble



bberry91
21 Feb 2012, 04:51 PM
I am having issues with this code. i type in random credentials, and nothing shows up after this code. if i type in a valid username like admin that is in the database, the page works fine. why won't it run properly?


$uname = mysql_real_escape_string($_POST['uname']);
$pword = mysql_real_escape_string($_POST['pword']);
$query = mysql_query("SELECT uname, pword, admin, active FROM members WHERE uname='admin'");
$row = mysql_fetch_array($query) or die(mysql_error());

this code will work. but instead of 'admin', i will put $uname.

bberry91
21 Feb 2012, 05:00 PM
nevermind... fixed by doing this...


if(mysql_num_rows($query) != 0)
{
$row = mysql_fetch_array($query) or die(mysql_error());

i guess it was getting hung up on retrieving records that were not in the db?