MySQL troubles

Luigi-San

New Member
Messages
14
Reaction score
0
Points
0
When I try to view threads on my forum, the posts don't show up and I get the following error:

Code:
[B]Warning[/B]:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [B]/home/luigisan/public_html/[URL="http://yiteamforums.it.cx/thread.php"]yiteamforums.it.cx/thread.php[/URL][/B] on line [B]162[/B]

Help!
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
In the script thread.php, on line 162, it tries to read the results of a MySQL query.
The problem is that the results it is trying to read is not valid.
That us usually because the query was not properly constructed. It can also be because you never connedted to the database.

Without actually seeing the code from thread.php, there is very little we can do to help you.
 

Luigi-San

New Member
Messages
14
Reaction score
0
Points
0
In the script thread.php, on line 162, it tries to read the results of a MySQL query.
The problem is that the results it is trying to read is not valid.
That us usually because the query was not properly constructed. It can also be because you never connedted to the database.

Without actually seeing the code from thread.php, there is very little we can do to help you.

Here's the code:
 

Attachments

  • threadphp.txt
    11 KB · Views: 77

marshian

New Member
Messages
526
Reaction score
9
Points
0
The error is in line 135 in the query. I think the part "FROM posts p,posts_text" is wrong. As far as I know it's not possible to select from two tables, so that wouldn't be correct.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
The error is in line 135 in the query. I think the part "FROM posts p,posts_text" is wrong. As far as I know it's not possible to select from two tables, so that wouldn't be correct.

Yes you can. It's called a join.

Don't have time right now, will post some suggestions in about two hours.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Here's a quick one (and probably Descalzo's first suggestion): on line 136, insert a test on the result of the query, and print the MySQL error message if $posts is false.
PHP:
	if (False === $posts) {
		echo mysql_error();
	}
Once you've got the error message, comment out the new code and post the error here. Once your issue is resolved, delete the new code.

If you had written the script, the proper solution would be to test the query results immediately before the for loop that calls mysql_fetch_array, and only enter the loop if the result is valid.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
What I would do....

Code:
$min=$ppp*$page;   // FIND THIS TO BEGIN EDITS...

  // write SQL queries as separate strings, so you can see what they actually are,
 // not what you think they are 
if($id){
  $sqlquery1= "SELECT p.*,text$sfields,edited,tagval,u.id uid,name,$ufields,regdate FROM posts p,posts_text LEFT JOIN users u ON p.user=u.id WHERE thread=$id AND p.id=pid ORDER BY p.id LIMIT $min,$ppp";
  $posts=mysql_query($sqlquery1);
  if (False === $posts) { 
        echo "Error with \$id = $id <br/>";
        echo mysql_error(); 
        echo "<br/>SQL: $sqlquery1 " ;
  }

} elseif($usr){
  $thread[replies]=mysql_result(mysql_query("SELECT count(*) FROM posts WHERE user=$usr"),0,0)-1;

  $sqlquery2 = "SELECT p.*,text$sfields,edited,tagval,u.id uid,name,$ufields,regdate FROM posts p,posts_text LEFT JOIN users u ON p.user=u.id WHERE user=$usr AND p.id=pid ORDER BY p.id LIMIT $min,$ppp" ;
  $posts=mysql_query($sqlquery2);

  if (False === $posts) { 
        echo "Error with \$usr = $usr <br/>";
        echo mysql_error(); 
        echo "<br/>SQL: $sqlquery2 " ;
  }
    }
 
Top