I can't retrieve info from db to display on page??

goldy300

New Member
Messages
33
Reaction score
0
Points
0
I'm trying to retrieve row[0] from pages table in the db but I keep getting this error:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/daniel/public_html/govpetitions/index.php on line 76

This is my code:

PHP:
include ("database.inc");
                    
                    $query = "SELECT * FROM pages WHERE pages_id= $id";
                    $mysql_result=mysql_query($query,$conn);
                    $row=mysql_fetch_row($mysql_result);

                    
                    echo $row[0];
I would like it if someone could chat with me through msn to work this out... and I'll send whatever files to you for you to look at, I'll implement changes and upload live to check. I want to get this sorted out quickly. I've got 2 weeks before I have to finish this and I've got a lot to do.

email me airbrushkits@live.com with your email and add me to msn
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
The query looks fine but what is $id set to?

When in doubt replace:
Code:
[COLOR=#000000][COLOR=#007700][/COLOR][COLOR=#0000BB]$mysql_result[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]mysql_query[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$query[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]$conn[/COLOR][COLOR=#007700]);

With

Code:
[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700][/COLOR][COLOR=#0000BB]$mysql_result[/COLOR][COLOR=#007700]=[/COLOR][COLOR=#0000BB]mysql_query[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$query[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]$conn[/COLOR][COLOR=#007700]) or die($query . "<br/>" . mysql_error());

Last part'll return the query, a line-break, then the error that is actually occuring, which should help narrow down what is actually causing the problem :)
[/COLOR][/COLOR]
 

mephis

New Member
Messages
39
Reaction score
0
Points
0
Two things could be wrong here:

1) Like Livewire said: is $id set, and if so, what is it set to?
If it's set to an INT then it's fine, if not:
PHP:
$query = "SELECT * FROM pages WHERE pages_id='$id'";
(notice the single quotes around $id)

2) I assume you are making the connection to your database in the file "database.inc", but is $conn a valid connection?
 

goldy30

New Member
Messages
60
Reaction score
0
Points
0
Ive had help and fixed some of the problem.



I didn't understand about the pages_id=$id... I thought the $id stayed that way but the person who helped me changed it to '0'.

PHP:
$query = "SELECT * FROM pages WHERE pages_id='0'";

Now I need help with inserting title and blurb in the pages database. contact me on msn asap
 
Last edited:
Top