Solved

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

Posted on 2011-02-21
6
459 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:shinuq
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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:
shinuq 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now