MxpUnk Posted October 25, 2005 Share Posted October 25, 2005 I'm creating a game, strictly using PhP, and Mysql. I'm very new to both, but good enough to manage through making this, but suddenly I have gotten stuck on something. I'm getting an error as follows: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/elitewar/public_html/view.php on line 7 No such player. I'm not sure.. I'm stumped... f you know what this is, please contact me at; haggardskater57@gmail.com help would be greatly appreciated.! Quote Link to comment Share on other sites More sharing options...
crispytown Posted October 25, 2005 Share Posted October 25, 2005 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/elitewar/public_html/view.php on line 7 No such player. On line 7 of your view.php file there should be a mysql query statement. It is not currect. Check that statement in phpmyadmin or a different mysql query tool. The reason could be a few different ones without looking at your code. 1. a variable might not be getting set... you you might want to check each with isset() function to make sure it was set. 2. you misspelled your fields titles or have the where condition out of wack. Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 25, 2005 Author Share Posted October 25, 2005 On line 7 of your view.php file there should be a mysql query statement. It is not currect. Check that statement in phpmyadmin or a different mysql query tool. The reason could be a few different ones without looking at your code. 1. a variable might not be getting set... you you might want to check each with isset() function to make sure it was set. 2. you misspelled your fields titles or have the where condition out of wack. 310573[/snapback] Hey, thats a ton man.!! Let me try this, and repost my results. Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 25, 2005 Author Share Posted October 25, 2005 Here is part of the code.. I didn't know if this is where i'm getting the error, but it was the only place that seemed logical to be getting an error... So here is the code.. like i said before im still a noob at this, so if i seem like a retard im sorry im trying to learn Code <?php $id=$_GET['id']; $view = mysql_fetch_array(mysql_query("select * from players where id=$id")); if (empty ($view['id'])) { print "No such player."; include("footer.php"); exit; } Error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/elitewar/public_html/view.php on line 7 No such player. Quote Link to comment Share on other sites More sharing options...
widgetapps Posted October 25, 2005 Share Posted October 25, 2005 There's a problem with your SQL. To find out what error it is, add the following code just before your if(empty(...) line: echo mysql_error(); Here is part of the code.. I didn't know if this is where i'm getting the error, but it was the only place that seemed logical to be getting an error... So here is the code.. like i said before im still a noob at this, so if i seem like a retard im sorry im trying to learn Code <?php $id=$_GET['id']; $view = mysql_fetch_array(mysql_query("select * from players where id=$id")); if (empty ($view['id'])) { print "No such player."; include("footer.php"); exit; } Error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/elitewar/public_html/view.php on line 7 No such player. 310712[/snapback] Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 25, 2005 Author Share Posted October 25, 2005 When i added that echo mysql_error(); i got the following: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/elitewar/public_html/view.php on line 7 You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1No such player. Quote Link to comment Share on other sites More sharing options...
crispytown Posted October 25, 2005 Share Posted October 25, 2005 Try this out ... [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php $id[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]$_GET[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'id\'[/span][span style=\"color:#007700\"]]; [/span][span style=\"color:#0000BB\"]$q[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#DD0000\"]\"SELECT * FROM players WHERE id=\'$id\'\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$view [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_fetch_array[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$q[/span][span style=\"color:#007700\"]) or die ([/span][span style=\"color:#DD0000\"]\"Could not execute query : $q.\" [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]())); if (empty ([/span][span style=\"color:#0000BB\"]$view[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'id\'[/span][span style=\"color:#007700\"]])) { print [/span][span style=\"color:#DD0000\"]\"No such player.\"[/span][span style=\"color:#007700\"]; include([/span][span style=\"color:#DD0000\"]\"footer.php\"[/span][span style=\"color:#007700\"]); exit; }[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 25, 2005 Author Share Posted October 25, 2005 alright let me give it a try. and thanks for for helpin Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 25, 2005 Author Share Posted October 25, 2005 Try this out ... [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\\\"color:#0000BB\\\"]<?php $id[/span][span style=\\\"color:#007700\\\"]=[/span][span style=\\\"color:#0000BB\\\"]$_GET[/span][span style=\\\"color:#007700\\\"][[/span][span style=\\\"color:#DD0000\\\"]\'id\'[/span][span style=\\\"color:#007700\\\"]]; [/span][span style=\\\"color:#0000BB\\\"]$q[/span][span style=\\\"color:#007700\\\"]=[/span][span style=\\\"color:#DD0000\\\"]\\\"SELECT * FROM players WHERE id=\'$id\'\\\"[/span][span style=\\\"color:#007700\\\"]; [/span][span style=\\\"color:#0000BB\\\"]$view [/span][span style=\\\"color:#007700\\\"]= [/span][span style=\\\"color:#0000BB\\\"]mysql_fetch_array[/span][span style=\\\"color:#007700\\\"]([/span][span style=\\\"color:#0000BB\\\"]mysql_query[/span][span style=\\\"color:#007700\\\"]([/span][span style=\\\"color:#0000BB\\\"]$q[/span][span style=\\\"color:#007700\\\"]) or die ([/span][span style=\\\"color:#DD0000\\\"]\\\"Could not execute query : $q.\\\" [/span][span style=\\\"color:#007700\\\"]. [/span][span style=\\\"color:#0000BB\\\"]mysql_error[/span][span style=\\\"color:#007700\\\"]())); if (empty ([/span][span style=\\\"color:#0000BB\\\"]$view[/span][span style=\\\"color:#007700\\\"][[/span][span style=\\\"color:#DD0000\\\"]\'id\'[/span][span style=\\\"color:#007700\\\"]])) { print [/span][span style=\\\"color:#DD0000\\\"]\\\"No such player.\\\"[/span][span style=\\\"color:#007700\\\"]; include([/span][span style=\\\"color:#DD0000\\\"]\\\"footer.php\\\"[/span][span style=\\\"color:#007700\\\"]); exit; }[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] 310897[/snapback] tried that. didn't work Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 25, 2005 Author Share Posted October 25, 2005 Oh shit. I tried what i was told to do, and then i put back in my old code. Usually I get that error but this time I didn't. But theres still a problem. It SEMI works. I don't get any errors, but look i get all my code on the page with the layout and all. I'll show a screen shot, hold on let me get it. http://i6.photobucket.com/albums/y227/Xelerate/favor.jpg Thats what im getting now.. :-/ atleast it SEMI works. Please help, and thanks for the help so far! Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 25, 2005 Author Share Posted October 25, 2005 Ok, fixed that problem with the screen shot. it was just a typing error. But now i'm back to my original problem. lol.. Quote Link to comment Share on other sites More sharing options...
crispytown Posted October 26, 2005 Share Posted October 26, 2005 What is your mysql table structure like? This is how I would do this personaly. I changed your code a little bit to fit into what I would do. [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php $id[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]$_GET[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'id\'[/span][span style=\"color:#007700\"]]; [/span][span style=\"color:#0000BB\"]$q [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"SELECT * FROM players WHERE id=\'$id\'\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$result [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$q[/span][span style=\"color:#007700\"]) or die ([/span][span style=\"color:#DD0000\"]\"Could not execute query : $q.\" [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]()); [/span][span style=\"color:#0000BB\"]$view [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_fetch_array[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$result[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]MYSQL_ASSOC[/span][span style=\"color:#007700\"]); if (empty([/span][span style=\"color:#0000BB\"]$view[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'id\'[/span][span style=\"color:#007700\"]])) { print [/span][span style=\"color:#DD0000\"]\"No such player.\"[/span][span style=\"color:#007700\"]; include([/span][span style=\"color:#DD0000\"]\"footer.php\"[/span][span style=\"color:#007700\"]); exit; }[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] Quote Link to comment Share on other sites More sharing options...
DaviDJ_G Posted October 26, 2005 Share Posted October 26, 2005 There has been a simple mistake here where you have mistaken $_GET['id'] when in the url of the screenshot it has view.php?view= so it should be $_GET['view'] Here i have made changes and also done a check to see if $_GET['view'] exists <?php $id = intval($_GET['view']); // // Checks to see if the ?view= has been set or not // if ( !isset($id) ) { print 'No ID entered.'; include("footer.php"); exit; } // // Query to select the player from the players table // $sql = "SELECT * FROM players WHERE id = $id"; // // puts the query into $result but also checks to see if it fails and returns an error // if ( !($result = mysql_query($sql)) ) { print 'Could not select player from database.'; include("footer.php"); exit; } // // unsets the $sql variable so it doesnt interfere with any other $sql variables set // unset($sql); // // if it has got this far it will put the result of the query into the $view variable // $view = mysql_fetch_array($result);] // // Frees up the result as we have the query results in $view now // mysql_free_result($result); ?> So this is the way to do it and this will now work if you use ?view=1 for showing a player Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 27, 2005 Author Share Posted October 27, 2005 no, daviddj, sorry to say it didn't work. Just gave me more errors. New error: White screen with; Parse error: parse error, unexpected ']' in /home/elitewar/public_html/view.php on line 43 There has been a simple mistake here where you have mistaken $_GET['id'] when in the url of the screenshot it has view.php?view= so it should be $_GET['view'] Here i have made changes and also done a check to see if $_GET['view'] exists <?php $id = intval($_GET['view']); // // Checks to see if the ?view= has been set or not // if ( !isset($id) ) { print 'No ID entered.'; include("footer.php"); exit; } // // Query to select the player from the players table // $sql = "SELECT * FROM players WHERE id = $id"; // // puts the query into $result but also checks to see if it fails and returns an error // if ( !($result = mysql_query($sql)) ) { print 'Could not select player from database.'; include("footer.php"); exit; } // // unsets the $sql variable so it doesnt interfere with any other $sql variables set // unset($sql); // // if it has got this far it will put the result of the query into the $view variable // $view = mysql_fetch_array($result);] // // Frees up the result as we have the query results in $view now // mysql_free_result($result); ?> So this is the way to do it and this will now work if you use ?view=1 for showing a player 311199[/snapback] Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 29, 2005 Author Share Posted October 29, 2005 oh well, I guess nothings working. I've kinda ignored the whole matter for a few days and started on some other parts of the game, but I keep coming back to this problem, and this is the main thing that I need to fix. :| well, if anyone has any more ideas, please post! All are appreciated! Quote Link to comment Share on other sites More sharing options...
MxpUnk Posted October 30, 2005 Author Share Posted October 30, 2005 W000T I finally fixed it. I feel like a total idiot also. It was the most simple mistake in the entire world. My Code now: <?php $view=$_GET['id']; $q = "SELECT * FROM players WHERE id='$id'"; $result = mysql_query($q) or die ("Could not execute query : $q." . mysql_error()); $view = mysql_fetch_array($result, MYSQL_ASSOC); if (empty($view['id'])) { print "I'm sorry there is no user with that ID Please Try again."; include("footer.php"); exit; } LOL, I had <?php $id=$_Get['id']; which was my problem! thanks for the help everyone! (Im recruiting some people to help admin the game, and code, so if you wanna help out a sweet job, message me!) Quote Link to comment 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.