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.
Need Help as to why I am getting an error using mysql_fetch
Moderator: General Moderators
Re: Need Help as to why I am getting an error using mysql_fetch
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'];
}
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'];
}
Re: Need Help as to why I am getting an error using mysql_fetch
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.
I think this one should be moved to the PHP Code section? Done.