Click to See Complete Forum and Search --> : A MySQL fetch error with PHP


firman
08-08-2006, 02:58 PM
<?php

require ('../header.php');

// calls the side links of the page
require ('../sub_programs/sub_sidelinks.php');


$dbh=mysql_connect ('localhost', 'firmanco_psfc', 'computate') or die ('I cannot connect to the database because" ' . mysql_error());
mysql_select_db ('firmanco_psfc');

$is_a_user = "no";

$query = "SELECT * FROM users WHERE Username = '{$_GET['username']}' AND Random_Activation_Key = '{$_GET['activation_key']}' AND Email_Address = '{$_GET['email_address']}' AND Member_Status = 'inactive'";

if ($r = mysql_query ($query)) {

while ($row = mysql_fetch_array ($r)) {

$is_a_user = 'yes';

$query = "UPDATE users SET Member_Status= 'active' WHERE Email_Address = '{$_GET['email_address']}' AND Username ='{$_GET['username']}' AND Random_Activation_Key = '{$_GET['activation_key']}' ";

$r = mysql_query ($query); //EXECUTE the QUERY.

print "You are now Active";
}
}

if ($is_a_user == "no") {

print "You are not signed up. Please Register.";

}



I then recieve the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/firmanco/public_html/prestonsteve/users/activate.php on line 18


What could the issue be? My coding seems correct to me?

dstran
08-08-2006, 03:04 PM
I think it means its not getting any data back from your query. try to use a debug statement

like
echo "Debug: -$query-";

to make sure you are getting the correct sql you want for your code.
if it is, try executing that sql to see your data set.

hope that helps.

firman
08-08-2006, 03:09 PM
The weird thing is... My UPDATE command still runs and works. so what could be wrong?

NogDog
08-08-2006, 07:43 PM
That error message almost always means that MySQL was unable to parse your query, therefore mysql_query() returned FALSE rather than a resource ID. (Even if no matches were found, you'd still get a resource ID if the query was valid.) Always assume a query might fail, and therefore check the result before trying to use it. The simplest way is to use the "or die()" pattern:

$r = mysql_query($query) or die("Query failed: $query - " . mysql_error());