Solved

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

Posted on 2011-02-21
6
464 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using in clause in query with many values 7 49
Multilanguage Database Design in MySQL 5 107
Mysql Crashing Intermittently 16 103
Creating Functions in phpMyAdmin 8 11
Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

785 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