Solved

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

Posted on 2011-02-21
6
468 Views
Last Modified: 2012-05-11
Cannot figure out why I am getting this error with this code, driving me crazy. Here is even the weirder thing. The code executes correctly, it does exactly what its supposed to do but i get this error. I even add the or die mysql error thing after the query to show me more detail and it shows me nothing. What the heck am I doing wrong?
<? include ('connect.php'); ?>
<? session_start(); ?>
<?
if ($session_user_logged = true) {
	$sql = "SELECT * FROM messages WHERE message_id = '$message_id'";
	$result = mysql_db_query($db,$sql,$cid);
	while ($row = mysql_fetch_array($result)) {
		if (!empty($row['hide'])) {
			$sql = "DELETE FROM messages WHERE message_id = '$message_id'";
			$result = mysql_db_query($db,$sql,$cid);
			if ($result) {
				echo '<meta http-equiv="refresh" content="0;url=../messages.php">';
			} else {
				session_register("error");
				$error = "There was a problem trying to post your status, please try again.";
				echo '<meta http-equiv="refresh" content="0;url=../messages.php">';
			}
		} else {
			$sql = "UPDATE messages SET hide = '$session_user_id' WHERE message_id = '$message_id'";
			$result = mysql_db_query($db,$sql,$cid);
			if ($result) {
				echo '<meta http-equiv="refresh" content="0;url=../messages.php">';
			} else {
				session_register("error");
				$error = "There was a problem trying to post your status, please try again.";
				echo '<meta http-equiv="refresh" content="0;url=../messages.php">';
			}
		}
	}
} else {
	session_register("error");
	$error = "You have to be logged in as the correct user to use this.";
	echo '<meta http-equiv="refresh" content="0;url=../index.php">';
}
?>

Open in new window

0
Comment
Question by:cbielich
  • 2
  • 2
  • 2
6 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 34948943
try like this,
<? include ('connect.php'); ?>
<? session_start(); ?>
<?
if ($session_user_logged = true) {
	$sql = "SELECT * FROM messages WHERE message_id = '$message_id'";
	$result = mysql_db_query($db,$sql,$cid) or die("error in connection ".mysql_error());
	
	$num_rows = mysql_num_rows($result);
	
	if ($num_rows > 0) {
		while ($row = mysql_fetch_array($result)) {
			if (!empty($row['hide'])) {
				$sql = "DELETE FROM messages WHERE message_id = '$message_id'";
				$result = mysql_db_query($db,$sql,$cid);
				if ($result) {
					echo '<meta http-equiv="refresh" content="0;url=../messages.php">';
				} else {
					session_register("error");
					$error = "There was a problem trying to post your status, please try again.";
					echo '<meta http-equiv="refresh" content="0;url=../messages.php">';
				}
			} else {
				$sql = "UPDATE messages SET hide = '$session_user_id' WHERE message_id = '$message_id'";
				$result = mysql_db_query($db,$sql,$cid);
				if ($result) {
					echo '<meta http-equiv="refresh" content="0;url=../messages.php">';
				} else {
					session_register("error");
					$error = "There was a problem trying to post your status, please try again.";
					echo '<meta http-equiv="refresh" content="0;url=../messages.php">';
				}
			}
		}
	} // for num row
} else {
	session_register("error");
	$error = "You have to be logged in as the correct user to use this.";
	echo '<meta http-equiv="refresh" content="0;url=../index.php">';
}
?>

Open in new window

0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 34948946
which line the error occur?
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 34948954
It seems, the debugging is disabled in your script. In the top of the page add these two lines

error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors",1);

This will show up which line is causing the error.

Hope this Helps

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 1

Author Comment

by:cbielich
ID: 34948955
Here is what prints out


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/g/u/i/guildfit/html/eaccountabilities/includes/remove_message.php on line 11

That's it
0
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 500 total points
ID: 34948963
The problem is with the $result  variable, You are using the $result variable in the

while ($row = mysql_fetch_array($result)) {

Also you are reassigning it in the delete and update statement, that naturally wont work.


$sql = "DELETE FROM messages WHERE message_id = '$message_id'";
$result_del = mysql_db_query($db,$sql,$cid);
if ($result_del) {

same you need to do for the update statement.

Hope this helps
0
 
LVL 1

Author Comment

by:cbielich
ID: 34948973
OMG dont take this the wrong way but I love you, IT WORKED!!!!!!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question