Jump to content

[SOLVED] Warning: mysql_fetch_array(): ... not a valid MySQL result


Goldeneye

Recommended Posts

So my problem is that I get this constant "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource" error on these new pages I'm creating (such as my Private Messaging System, my Link System, and this page). I partially know what it means, but I made sure the database fields matched the queried fields and that there was atleast a dummy entry in there, but still... nothing.

 

The PHP

<?php
session_start();
include 'globals.php';
connectSQL();

if($_SESSION['userrank'] < 4){header('Location: index.php');}
else {
	gHeader('Site Administration'); // The HTML head/page title
	echo '<ul class="subnavul">'; //Sub-Navigation
	echo '<li class="subnavli"><a href="?boards">Boards</a></li>';
	echo '</ul>';
	if(isset($_GET['boards'])){
		echo '<div class="pagetitle">Boards</div>';
		$notequery = mysql_query("SELECT 
		`noteid`, 
		`time`, 
		`userid`, 
		`username`, 
		`reason`, 
		`getid1`, 
		`getid2`, 
		`getid3` 
		FROM `notifications` WHERE `type`=0 AND `status`=0 ORDER BY `noteid` ASC") || die(mysql_error($query));
		$noterow = mysql_fetch_array($notequery);
		echo $noterow['userid'];
	} else {
		echo '<p>Welcome</p>';
	}
	gFooter();
}
?>

 

And the Database Structure

<?php
CREATE TABLE `notifications` (
  `noteid` mediumint(9) NOT NULL auto_increment,
  `type` int(2) NOT NULL,
  `time` int(11) NOT NULL,
  `userid` mediumint(9) NOT NULL,
  `username` varchar(100) NOT NULL,
  `reason` blob NOT NULL,
  `status` int(1) NOT NULL,
  `getid1` int(20) NOT NULL,
  `getid2` int(20) NOT NULL,
  `getid3` bigint(20) unsigned NOT NULL,
  PRIMARY KEY  (`noteid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
?>

 

I don't think it's because I use isset($_GET['boards']) instead of something $_GET['area']==boards. And I'm certain I have no typo's in my mysql_query(). Is my field indexing wrong? If anyone can tell me anything that's wrong, please do, because this is beginning to anger me.

 

A preemptive thanks to you.

That's exactly what's boggling me; I'm sure the code is correct. I even tried using mysql_fetch_assoc() and list($dbvar1, $dbvar2, $dbvar3...) = mysql_fetch_row(), though that also returned the same invalid result resource error. This worked with my forum, but not with any new pages.. I'm using the exact same functions in the exact same way, as well.

After experimenting

 

<?
include "db.php"; 

$q = mysql_query("SELECT locname FROM baagriddata") || die(mysql_error()) ;
$r = mysql_fetch_row($q);
var_dump($q);
?>

gives-->
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\test\noname4.php on line 5
bool(true) 

 

but

<?
include "db.php"; 

$q = mysql_query("SELECT locname FROM baagriddata") or die(mysql_error()) ;
$r = mysql_fetch_row($q);
var_dump($q);
?>

gives -->
resource(3) of type (mysql result)

 

Change "||" to "or"

It works because that isn't a comparison, it's a keyword.

 

You can substitute it into a comparison, because it's just a bitwise operator meaning the same thing. Outside of the comparison "or" is a language construct just like if/else/return etc, you can't just substitute it in.

 

There's no difference when being used as a bitwise operator (1=1 or 2=2) is the same as (1=1 || 2=2) but it can ONLY be used in a conditional statement.

There's no difference when being used as a bitwise operator (1=1 or 2=2) is the same as (1=1 || 2=2) ...

 

Not true.

 

Their operator precedences are completely different. See table

 

http://www.php.net/manual/en/language.operators.php

 

 

(BTW "|" is the bitwise "or", "||" is a logical operator)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.