944,070 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3307
  • PHP RSS
Mar 13th, 2006
0

mysql_fetch_array problem

Expand Post »
Hello.

I have the following errors:

Quote ...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/winnie/public_html/pqQuiz/lib/templates.php on line 13

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/winnie/public_html/pqQuiz/lib/templates.php on line 13

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/winnie/public_html/pqQuiz/lib/templates.php on line 13
Lines 1-16 of templates.php shows the following:

Quote ...
function loadTemplates() {
global $templates;
if( !isset($_SESSION['user']) || $_SESSION['user'] == "" ){
$selected = "templates";
}
else{
$selected = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE user='".$_SESSION['user']."'"));
$selected = $selected['template'];
}
$loadTemplates = mysql_query("SELECT * FROM $selected");
while($loadTemplates = mysql_fetch_array($loadTemplates)){
$templates[$loadTemplates['name']] = $loadTemplates['code'];
}
}

Could anyone help me solve this problem?

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lizard is offline Offline
1 posts
since Mar 2006
Mar 13th, 2006
0

Re: mysql_fetch_array problem

The problem is exactly what the error message states. The resource is not a valid MySql resource. This is because the query is invalid or not producing any data.

Instead of building your SQL statement inside the mysql_query statement directly, build it in a variable then use that variable in the mysql_query statement. This allows you to echo out the contents of the $sql variable.

So do something like this:
[PHP]
$sql = "SELECT * FROM users WHERE user='".$_SESSION['user']."'";
echo $sql;
$rs = mysql_fetch_array(mysql_query($sql));
[/PHP]
The echo statement will display the SQL that is being passed to your database. If you don't see any obvious errors in the statement, then copy and paste that query in a tool like phpMyAdmin's query tool to see what happens when you try to execute the statement.

What I'm suggesting is troubleshooting 101. Break the code down into one line at a time. Make sure each line is working before moving onto the next. If a line causes an error, break that line down into the smallest parts possible and test each aspect of the line. With PHP, your #1 debugging tool is the echo or print statements. Simply echo out variables and such to find what is happening.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: wht is HTML,PHP,CGI(Common Gateway Interface)
Next Thread in PHP Forum Timeline: need help with a php issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC