Jump to content

Error : Please help me :)


beansandsausages

Recommended Posts

Hey all. I have a script that has been working fine, now all of a sudden i get this error :

 

 Warning: mysql_fetch_assoc(): 5 is not a valid MySQL result resource in c:\phpdev\www\public\mem.php on line 275

 

Thhis is the block of code the error line is referring to :

 

$sql = "SELECT * FROM `news` ORDER BY id DESC LIMIT 0,7";
				$result = mysql_query($sql);
				if (!$result) {
    				echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    					exit;
				}

				if (mysql_num_rows($result) == 0) {
    				echo "<p>No news posted. </div></p>";
    					include_once("layout_all/bottom.php");
				exit;
				}

			while ($row = mysql_fetch_assoc($result)) { 
    				
			$row[message] = str_replace($word, $image, $row[message]);
			$row[message] = str_replace($color, $text, $row[message]);
			$row[message] = str_replace($effect, $status, $row[message]);


			echo "<p> {$row["date"]} : {$row["time"]} : Poster {$row["poster"]} <br /> {$row["message"]} </p> <br /> "; 
				if($info[security] >= 8 ) { echo "<p><form action=\"?action=delete\" method=\"POST\"><input type=\"hidden\" name=\"delete_id\" id=\"delete_id\" value=\"{$row['id']}\"><input type=\"submit\" value=\"Delete Post\"> </form> <form action=\"?action=edit\" method=\"POST\"><input type=\"hidden\" name=\"edit_id\" id=\"edit_id\" value=\"{$row['id']}\"><input type=\"submit\" value=\"Edit Post\"></form></p> <br />"; } 




			mysql_free_result($result);


			echo " 	</div>  ";
			}

Any ideas people thanx

Link to comment
https://forums.phpfreaks.com/topic/93089-error-please-help-me/
Share on other sites

In case you did not understand, that instruction "kills" your result. Actually, as it was inside the cycle, you got the error when you tried to read the second line. That's why 'limit 1' works.

It makes sense to have it when you're finished with your result. Anyway you don't need it (php does it for you at the end of the script), unless you need much more time and/or memory after processing your result.

Link to comment
https://forums.phpfreaks.com/topic/93089-error-please-help-me/#findComment-477117
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.