Need Help as to why I am getting an error using mysql_fetch

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
botlife1
Forum Newbie
Posts: 3
Joined: Sun Sep 21, 2008 3:22 pm

Need Help as to why I am getting an error using mysql_fetch

Post by botlife1 »

Hey There,

I am trying to retrieve a username from my database and I keep getting this error.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Here is the simple code.

$reg_pass = $_POST['reg_pass'];
$reg_email = $_POST['reg_email'];
$result = " SELECT * FROM login WHERE reg_email='$reg_email' AND reg_pass='$reg_pass' ";
if (!$result) {
echo mysql_error();
exit;
}
while($row = mysql_fetch_array($result) )
{


echo $row['reg_firstname'];

}

Please help as this is driving me crazy. The error is coming from the myswl_fetch_array line.
botlife1
Forum Newbie
Posts: 3
Joined: Sun Sep 21, 2008 3:22 pm

Re: Need Help as to why I am getting an error using mysql_fetch

Post by botlife1 »

Okay nevermind. I made a query and it works now. I knew I was doing something so simply wrong.

here is the corrected version of the code that works now.

$reg_pass = $_POST['reg_pass'];
$reg_email = $_POST['reg_email'];
$query = " SELECT * FROM login WHERE reg_email='$reg_email' AND reg_pass='$reg_pass' ";
$result = mysql_query($query) or die (mysql_error());
if (!$result) {
echo mysql_error();
exit;
}
while($row = mysql_fetch_array($result) )
{


echo $row['reg_firstname'];

}
User avatar
8ennett
Forum Commoner
Posts: 63
Joined: Sat Sep 06, 2008 7:05 am

Re: Need Help as to why I am getting an error using mysql_fetch

Post by 8ennett »

It's always the simple things, thank god PHP.ini only needs 2 lines changing so we can see where our mistakes are, took me a while to figure that one out!

I think this one should be moved to the PHP Code section? Done.
Post Reply