PHP & Mysql Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

PHP & Mysql Error

Post by mjseaden »

Hi

The following PHP code:

Code: Select all

$query = $_POSTї'query'];
            
            $result = mysql_query($query);
            
            if(!$result)
            {
                do_html_message('Error: Could not perform MySQL query - '.mysql_error());
                do_html_footer();
                exit();
            }

            $is_highlights = FALSE;

            while( $row = mysql_fetch_array( $result ) )
Produces the following warning:

Code: Select all

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/XXX/public_html/admin.php on line 108
For the following query:

Code: Select all

SELECT * FROM Properties WHERE ConsultancyID=2 ORDER BY PropertyTitle LIMIT 0,30
Any ideas?

Many thanks in advance

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Make sure the query comes in correct. Use the mysql_error() directly with the query.


WARNING executing a database query without validation is EXTREMELY dangerous.
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi Feyd,

I've echoed the query to check it's correct - the query shown above is a direct copy off the page. mysql_error() doesn't seem to give any clues.

...?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Did you check that you are connected properly with the DB before executing query :?:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have a feeling that mysql_fetch_array() isn't line 108. Maybe post the entire file.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

feyd wrote:I have a feeling that mysql_fetch_array() isn't line 108. Maybe post the entire file.
:lol: good point there, feyd :wink:
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi feyd,

Sorry for the delay, my internet connection just went down.

I can confirm from my editor that mysql_fetch_array is line 108.

Cheers

Mark
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Have you tried executing the query in phpmyadmin?

What about double checking field names and whether there really ARE any rows with the specifications listed in the query?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

if $_POST['query'] isn't an SQL line you're not going to get any results

Code: Select all

$query = $_POSTї'query']
$result = mysql_query("SELECT column FROM tablename WHERE something = '$query'");
That is most likely what you're wanting.
Post Reply