Goldeneye Posted May 25, 2008 Share Posted May 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/ Share on other sites More sharing options...
Barand Posted May 25, 2008 Share Posted May 25, 2008 try changing mysql_error($query) to mysql_error() Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/#findComment-549374 Share on other sites More sharing options...
Goldeneye Posted May 25, 2008 Author Share Posted May 25, 2008 Hmmm that didn't change the error message, or do anything, really. It's still occuring on line 24 which is the $noterow = mysql_fetch_array($notequery); line.. Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/#findComment-549378 Share on other sites More sharing options...
Barand Posted May 25, 2008 Share Posted May 25, 2008 I can't understand why mysql_error() isn't producing any output if $notequery is invalid. Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/#findComment-549382 Share on other sites More sharing options...
Goldeneye Posted May 25, 2008 Author Share Posted May 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/#findComment-549384 Share on other sites More sharing options...
Barand Posted May 25, 2008 Share Posted May 25, 2008 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" Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/#findComment-549386 Share on other sites More sharing options...
Goldeneye Posted May 25, 2008 Author Share Posted May 25, 2008 Wow it's actually displaying something now.. I didn't think there was a different between 'or' and '||' but not it's displaying the userid of the dummy entry; thanks a lot Barand! Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/#findComment-549625 Share on other sites More sharing options...
deadonarrival Posted May 25, 2008 Share Posted May 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/#findComment-549633 Share on other sites More sharing options...
Barand Posted May 25, 2008 Share Posted May 25, 2008 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) Link to comment https://forums.phpfreaks.com/topic/107151-solved-warning-mysql_fetch_array-not-a-valid-mysql-result/#findComment-549651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.