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
mjseaden
Forum Contributor
Posts: 458 Joined: Wed Mar 17, 2004 5:49 am
Post
by mjseaden » Fri Feb 25, 2005 8:12 am
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 25, 2005 8:16 am
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 » Fri Feb 25, 2005 8:27 am
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.
...?
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Fri Feb 25, 2005 8:36 am
Did you check that you are connected properly with the DB before executing query
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 25, 2005 8:39 am
I have a feeling that mysql_fetch_array() isn't line 108. Maybe post the entire file.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Fri Feb 25, 2005 8:42 am
feyd wrote: I have a feeling that mysql_fetch_array() isn't line 108. Maybe post the entire file.
good point there, feyd
mjseaden
Forum Contributor
Posts: 458 Joined: Wed Mar 17, 2004 5:49 am
Post
by mjseaden » Fri Feb 25, 2005 9:24 am
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 » Fri Feb 25, 2005 11:27 am
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?
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Feb 25, 2005 5:31 pm
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.