brandon99919 Posted June 22, 2009 Share Posted June 22, 2009 Here's the error that shows up: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 28 Here's the code itself: <?php $query = mysql_query("SELECT * FROM pokemon WHERE owner_id = '$userid' and p_slot = '1'"); $fetch = mysql_fetch_array($query); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 1' />"; } ?> and line 28 is the mysql_fetch_array function Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/ Share on other sites More sharing options...
gevans Posted June 22, 2009 Share Posted June 22, 2009 You have to execture the query first using mysql_query($query); <?php $query = mysql_query("SELECT * FROM pokemon WHERE owner_id = '$userid' and p_slot = '1'"); $result = mysql_query($query); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 1' />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861238 Share on other sites More sharing options...
gevans Posted June 22, 2009 Share Posted June 22, 2009 sorry, little typo; <?php $query = mysql_query("SELECT * FROM pokemon WHERE owner_id = '$userid' and p_slot = '1'"); $result = mysql_result($query); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 1' />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861241 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 it still gives the same error Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861276 Share on other sites More sharing options...
gevans Posted June 22, 2009 Share Posted June 22, 2009 Are you successfully connection to your db? Is $userid set, and is it what you think it should be. Output the query before running it to check it. Do some error checking on the query, is it successful, does it fail? Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861280 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 yea the database connection is good and when I tested the query it got back an error saying that the owner_id column doesn't exist. Turns out the column is actually called p_owner, so I changed it to that and ran the query and it was successful. And yea, the userid variable is set. I still get the same error even tho I fixed the problem with the where clause. ??? Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861284 Share on other sites More sharing options...
gevans Posted June 22, 2009 Share Posted June 22, 2009 So is this solved? Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861285 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 nahh the same error still shows up Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861289 Share on other sites More sharing options...
gevans Posted June 22, 2009 Share Posted June 22, 2009 If the query was successfuly you wouldn't be getting that error. Try this, <?php $query = mysql_query("SELECT * FROM `pokemon` WHERE `p_owner`=$userid AND `p_slot`= 1"); $result = mysql_query($query) or trigger_error('Query failed: ' . mysql_error($db), E_USER_ERROR); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 1' />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861292 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 now it gives this error: Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 28 Fatal error: Query failed: in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 28 Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861298 Share on other sites More sharing options...
gevans Posted June 22, 2009 Share Posted June 22, 2009 You have to forgive me, I've been working on stuff today that has led me to do the oppsite than help. Fixed Script bellow; <?php $query = mysql_query("SELECT * FROM `pokemon` WHERE `p_owner`=$userid AND `p_slot`= 1") or trigger_error('Query failed: ' . mysql_error($db), E_USER_ERROR); $fetch = mysql_fetch_array($query); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 1' />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861303 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 now it gives the same error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 29 Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861308 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 my bad for the double post, but yeah it still gives the same error =[ Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861311 Share on other sites More sharing options...
PFMaBiSmAd Posted June 22, 2009 Share Posted June 22, 2009 It's likely that the code you are posting is part of a loop and that the actual line with the error is not the posted code. Post your code from the start of your file through the end of any loop that is involved in what you are doing. The $db variable in the mysql_error() is also not helping and should be removed because it is not relevant to the OP's code. Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861319 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 here's the full code: <a onClick="subMenu('general_submenu', this);">General</a> <div id='general_submenu' class='sub_menu'> <a href='/index.php?page=news'>News</a> <a href='/index.php?page=promo'>Promo</a> <a href='/index.php?page=staff'>Staff</a> <a href='/index.php?page=logout'>Logout</a> </div> <a onClick="subMenu('myAccount_submenu', this);">My Account</a> <div id='myAccount_submenu' class='sub_menu'> <a href='/index.php?page=profile'>My Profile</a> </div> <a onClick="subMenu('myPokemon_submenu', this);">My Pokémon</a> <div id='myPokemon_submenu' class='sub_menu'> <a href='/index.php?page=stats'>Starter Stats</a> </div> <?php if($user_level == "Admin") { ?> <a onClick="subMenu('adminCP_submenu', this);">Admin CP</a> <div id='adminCP_submenu' class='sub_menu'> <a href='/index.php?page=gen'>Promo</a> </div><?php }?> <a href='#'>Master Quest</a> <div align='center'> <?php include('includes/basefile.php'); $query = mysql_query("SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot = '1'"); $result = mysql_query($query); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 1' />"; } ?> <?php $query = mysql_query("SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot = '2'"); $result = mysql_query($query); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 2' />"; } ?> <?php $query = mysql_query("SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot = '3'"); $result = mysql_query($query); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 3' />"; } ?><br /> <?php $query = mysql_query("SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot = '4'"); $result = mysql_query($query); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 4' />"; } ?> <?php $query = mysql_query("SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot = '5'"); $result = mysql_query($query); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 5' />"; } ?> <?php $query = mysql_query("SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot = '6'"); $result = mysql_query($query); $fetch = mysql_fetch_array($result); $p_icon1 = $fetch['p_icon']; $p_name1 = $fetch['p_name']; if (empty($p_name1)) { echo "<img src='{$p_icon}' alt='{$p_name1}' />"; } else { echo "<img src='pokemonball.gif' alt='slot 6' />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861321 Share on other sites More sharing options...
PFMaBiSmAd Posted June 22, 2009 Share Posted June 22, 2009 And the php error message from that code is? There is no way that code can work, because there are double mysql_query() statements in it. The easiest fix would be to change each of the leading mysql_query() statements so that the line just sets the $query variable with the query statement - $query = "SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot = '1'"; And you should be executing a single query that returns all the rows you want as a set, then you loop through them. Duplicating code usually wastes time due to the typo's made while fixing up the different values in it. Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861339 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 here's the errors: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 29 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 55 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 68 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 81 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\hshome\brandon9\pcprpg.com\menu_user.php on line 94 Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861352 Share on other sites More sharing options...
PFMaBiSmAd Posted June 22, 2009 Share Posted June 22, 2009 Back to ground zero. All that means is your query is failing and no one knows why. For troubleshooting purposes only, replace the lines making up your first query with the following - $query = "SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot = '1'"; $result = mysql_query($query) or die("Query failed: $query, " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861361 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 the errors are gone thanks for the help solved Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861368 Share on other sites More sharing options...
PFMaBiSmAd Posted June 22, 2009 Share Posted June 22, 2009 I'm guessing the original problem was the column name. You can replace all that php code with the following single query and a loop - Untested, but should work - <?php include('includes/basefile.php'); $query = "SELECT * FROM pokemon WHERE p_owner = '$userid' and p_slot IN('1','2','3','4','5','6') ORDER BY p_slot"; $result = mysql_query($query); $i = 1; while($row = mysql_fetch_array($result)){ $p_icon = $row['p_icon']; $p_name = $row['p_name']; if(!empty($p_name)){ echo "<img src='{$p_icon}' alt='{$p_name}' />"; } else { echo "<img src='pokemonball.gif' alt='slot {$i}' />"; } $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861371 Share on other sites More sharing options...
brandon99919 Posted June 22, 2009 Author Share Posted June 22, 2009 it only displays one image Quote Link to comment https://forums.phpfreaks.com/topic/163240-solved-warning-mysql_fetch_array/#findComment-861388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.