Jump to content


Photo

Msql Help!!


  • Please log in to reply
15 replies to this topic

#1 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 25 October 2005 - 05:33 AM

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.!

#2 crispytown

crispytown
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 25 October 2005 - 12:05 PM

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.


#3 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 25 October 2005 - 04:16 PM

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.

View Post


Hey, thats a ton man.!! Let me try this, and repost my results.

#4 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 25 October 2005 - 04:28 PM

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 :D

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.


#5 widgetapps

widgetapps
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationToronto

Posted 25 October 2005 - 04:32 PM

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 :D

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.

View Post



#6 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 25 October 2005 - 04:42 PM

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.

#7 crispytown

crispytown
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 25 October 2005 - 08:49 PM

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--]

#8 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 25 October 2005 - 08:57 PM

alright let me give it a try. and thanks for for helpin :)

#9 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 25 October 2005 - 10:39 PM

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--]

View Post


tried that. didn't work :(

#10 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 25 October 2005 - 10:58 PM

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.photobucke...erate/favor.jpg


Thats what im getting now.. :-/ atleast it SEMI works. Please help, and thanks for the help so far!

#11 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 25 October 2005 - 11:03 PM

Ok, fixed that problem with the screen shot. it was just a typing error. But now i'm back to my original problem. lol..

#12 crispytown

crispytown
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 26 October 2005 - 01:34 AM

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--]

#13 DaviDJ_G

DaviDJ_G
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 26 October 2005 - 12:53 PM

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

#14 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 27 October 2005 - 07:40 PM

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

View Post



#15 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 29 October 2005 - 09:46 PM

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!

#16 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 30 October 2005 - 07:08 PM

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! :D 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!)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users