Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Old 07-23-2006, 04:24 AM Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Extreme Talker

Posts: 217
Trades: 0
Iv gotten this stupid error plenty of times on my little project.. really anoying and I cant remember how to fix it...The stupid thing is I used the exact same code (only modified a bit) for a different page and everything works fine.

here is the code the error is talking about:
PHP Code:
$from = (($page $max_pm) - $max_pm);
$sql "SELECT * FROM $pmtable WHERE to='$username1' ORDER BY id DESC LIMIT $from$max_pm";
$result mysql_query($sql);


while(
$rows mysql_fetch_array($result)){
//bunch of html stuff goes here


I dont understand why its giving me this error!
Slick Nick is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-23-2006, 06:31 AM Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
This error usually means that the query failed, and as such $result is not set with the correct value. Add on an 'or die()' to the query so it looks like this:
PHP Code:
$from = (($page $max_pm) - $max_pm);
$sql "SELECT * FROM $pmtable WHERE to='$username1' ORDER BY id DESC LIMIT $from$max_pm";
$result mysql_query($sql) or die(mysql_error());


while(
$rows mysql_fetch_array($result)){
//bunch of html stuff goes here


This should print the MySQL error message out so you can tell what went wrong.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 07-23-2006, 05:26 PM Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Extreme Talker

Posts: 217
Trades: 0
Ok thanks, il get in the habit of using or die
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 07-25-2006, 12:22 PM Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resou
Super Talker

Posts: 111
Name: Jonathan
Location: Arizona, USA
Trades: 0
It's probably just a typo or reference to a variable that might not exist. In addition to doing die() you can also echo your query out to see what the query is querying.
Before your 'while' statement you could write.
Code:
echo $sql;
exit();
Then load your file in a browser to see what the string is querying the database with.

You could also take the query and put it into phpMyAdmin to see why the query isn't bringing any results. Then, once you get it corrected, put it back into your PHP script.
__________________

Please login or register to view this content. Registration is FREE
- Computer Repair over the internet!
pcoptimized is offline
Reply With Quote
View Public Profile Visit pcoptimized's homepage!
 
Old 07-25-2006, 11:35 PM Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resou
Extreme Talker

Posts: 217
Trades: 0
I managed to fix it but I still dont see what the problem was... I just copied and pasted some other code and carefully switched some stuff (which was what i did before, but i just did it again) and it fixed! There must of been a character or something missing because the file size was 1 byte less afterwards. Im not sure which was causing the problem though cause I went through the code about a dozen times and didnt see anything that would cause a problem.

Im having the exact same problem as before but with a different script.
Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, toUser, message) VALUES('test', 'V', 'test', 'test')' at line 1
and the sql is
PHP Code:
$sql1 "INSERT INTO $pmtable(subject, from, toUser, message) VALUES('$subject', '$username3', '$toUser', '$message')";
$result1 mysql_query($sql1) or die(mysql_error()); 
Slick Nick is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21286 seconds with 12 queries