Solved

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

Posted on 2011-02-21
6
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

627 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