Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-21
6
Medium Priority
?
475 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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
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 2000 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

926 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