Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9103
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9114
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9116
Share on other sites

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.

310712[/snapback]

 

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9117
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9118
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9134
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9139
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9141
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9145
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9158
Share on other sites

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]

 

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9194
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9253
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/2730-msql-help/#findComment-9264
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.