mysql_fetch_array(): supplied argument is not a valid MySQL

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
olly86
-


Joined: 25 Apr 2003
Posts: 993
Location: Wiltshire, UK

PostPosted: Wed Sep 15, 2004 5:56 pm    Post subject: mysql_fetch_array(): supplied argument is not a valid MySQL Reply with quote

when I run the following code, I receive this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Abyss Web Server\htdocs\hp\login.php on line 7
Code:
$sql = 'SELECT * FROM `author` WHERE 1 AND `author _name` = '.$_POST['username'];

// Run the query, identifying the connection
$queryResource = mysql_query($sql, $connection);

// Fetch rows from MySQL one at a time
while ($row = mysql_fetch_array($queryResource, MYSQL_ASSOC)) {
echo($row['author_id']);
}

I've used similar code before, but cannot see why this code is bombing out on line 7 (while ($row = mysql_fetch_array($queryResource, MYSQL_ASSOC)) {). any help will be greatly appreciated, thanks.

note their is more code to the script, but i've only shown the bits that I feel are relevant
_________________
Olly
Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Wed Sep 15, 2004 6:06 pm    Post subject: Reply with quote

Although I hardly use MySQL in my PHP programming , you can check the
official PHP website at www.php.net , I provided a link for this function below.

http://us4.php.net/manual/en/function.mysql-fetch-array.php
Back to top View user's profile Send private message Visit poster's website
hernanx
-


Joined: 15 Sep 2004
Posts: 1

PostPosted: Wed Sep 15, 2004 11:33 pm    Post subject: Reply with quote

Hi
mysql_fetch_array return FALSE if the query has problems, so I think that the problems is in the query line, the resource that make reference mysql_fetch_array come from the previous query.
Back to top View user's profile Send private message
olly86
-


Joined: 25 Apr 2003
Posts: 993
Location: Wiltshire, UK

PostPosted: Wed Sep 15, 2004 11:45 pm    Post subject: Re: mysql_fetch_array(): supplied argument is not a valid My Reply with quote

Code:
$sql = "SELECT * FROM `author` WHERE 1 AND `author_name`='".$_POST['username']."'";

I had a felling it would be something simple :( I'd missed the ' around the search criteria. Mind you when one is dyslexic these are frequent problems. :(
_________________
Olly
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group