Page 1 of 1

PHP & Mysql Error

Posted: Fri Feb 25, 2005 8:12 am
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

Posted: Fri Feb 25, 2005 8:16 am
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.

Posted: Fri Feb 25, 2005 8:27 am
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.

...?

Posted: Fri Feb 25, 2005 8:36 am
by n00b Saibot
Did you check that you are connected properly with the DB before executing query :?:

Posted: Fri Feb 25, 2005 8:39 am
by feyd
I have a feeling that mysql_fetch_array() isn't line 108. Maybe post the entire file.

Posted: Fri Feb 25, 2005 8:42 am
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:

Posted: Fri Feb 25, 2005 9:24 am
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

Posted: Fri Feb 25, 2005 11:27 am
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?

Posted: Fri Feb 25, 2005 5:31 pm
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.