|
|
|
| Web Hosting |
![]() ![]() |
Php Mysql Errors, Fetching arrays |
Apr 21 2007, 06:06 PM
Post
#1
|
|
|
Super Member Group: [HOSTED] Posts: 774 Joined: 12-July 06 From: Ontario, Canada Member No.: 14,464 myCENTs:42.53 |
I am deciding to make a Multiplayer Online RPG type game. I will be building it off of PHP and MySQL to ensure makimum compatibility with Astahost's services (and it makes it easier
All games of course have something similar to gold, units and points. Because this is a turn-based game, I have turns. Now for the problem: I am trying to echo the points, gold and turns to the main page of the game. I tried using mysql_result, mysql_fetch_array and also mysql_fetch_assoc. It doesn't work. Here is my code: CODE <?php require("db_connect.php"); $username = $_COOKIE['xtech_user']; $zbits = mysql_query("SELECT `zbits` FROM `players` WHERE `username`=$username"); while($row1 = mysql_fetch_array($zbits)) { echo "zBits: " . $row1['zbits'] . " | "; } $turns = mysql_query("SELECT `turns` FROM `players` WHERE `username`=$username"); while($row2 = mysql_fetch_array($turns)) { echo "zTurns: " . $row2['turns'] . " | "; } $zpoints = mysql_query("SELECT `zpoints` FROM `players` WHERE `username`=$username"); while($row3 = mysql_fetch_array($zpoints)) { echo "zPoints: " . $row3['zpoints'] . " "; } mysql_close(); ?> The required file is the database connection file, it is just a $con variable along with mysql_connect and mysql_select_db("gameDatabase",'$con'). I use that for everypage that requires a MySQL connection. I store the username in a cookie, so therefore I will retrieve the cookie value and put it in the variable $username. Now I want to get a column (field) value from the players table where the username is what that was declared in the cookie variable. When I run the mysql_query in the mysql_fetch_array, this error occurs: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/portal/public_html/game/head.php on line 13 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/portal/public_html/game/head.php on line 18 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/portal/public_html/game/head.php on line 23 I don't know what is causing this! I tried using SELECT * also, but the same error comes up. I would like to get this working soon. Please help with this. |
|
|
|
Apr 21 2007, 09:16 PM
Post
#2
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 1,053 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 myCENTs:36.94 |
Try adding single quotes around $username, because it is a string:
$query = "SELECT `zbits` FROM `players` WHERE `username`='$username'"; I am not sure if this is necessary, but as far as I can see, that is the only thing I would do in a different way. |
|
|
|
Apr 21 2007, 11:28 PM
Post
#3
|
|
|
Super Member Group: [HOSTED] Posts: 774 Joined: 12-July 06 From: Ontario, Canada Member No.: 14,464 myCENTs:42.53 |
Thank you! That automatically made it work! I thought variable names didn't need to be enclosed in quotes, but I guess it is necessary when you have them in MySQL functions. Now I need to add about 30-50 some more fields!
Topic solved. |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
3 | FirefoxRocks | 155 | 24th December 2008 - 01:43 PM Last post by: Quatrux |
|||
![]() |
8 | nakulgupta | 2,038 | 4th December 2008 - 05:26 AM Last post by: iG-tohir |
|||
![]() |
2 | magiccode9 | 164 | 17th November 2008 - 12:05 PM Last post by: magiccode9 |
|||
![]() |
5 | lonebyrd | 1,553 | 29th October 2008 - 11:00 PM Last post by: Guest |
|||
![]() |
11 | rckstr4lfe | 3,620 | 26th October 2008 - 03:54 PM Last post by: Guest |
|||
![]() |
3 | khalilov | 372 | 8th October 2008 - 05:27 AM Last post by: TavoxPeru |
|||
![]() |
9 | anzoone | 2,452 | 11th September 2008 - 06:56 AM Last post by: Guest |
|||
![]() |
10 | Houdini | 1,802 | 6th September 2008 - 07:02 AM Last post by: Guest |
|||
![]() |
11 | Alexandre Cisneiros | 2,121 | 4th September 2008 - 06:45 AM Last post by: Guest |
|||
![]() |
4 | wanhafizi | 1,413 | 28th August 2008 - 04:53 AM Last post by: Guest |
|||
![]() |
18 | lonebyrd | 2,788 | 18th August 2008 - 09:41 PM Last post by: Guest |
|||
![]() |
4 | aqaing | 868 | 10th August 2008 - 09:06 AM Last post by: TavoxPeru |
|||
![]() |
6 | demolaynyc | 961 | 7th August 2008 - 01:57 PM Last post by: Guest |
|||
![]() |
8 | warriors | 4,485 | 6th August 2008 - 09:00 AM Last post by: Guest |
|||
![]() |
1 | darkken | 844 | 31st July 2008 - 08:35 PM Last post by: Darasen |
|||
|
Lo-Fi Version | Time is now: 8th January 2009 - 02:09 AM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation




Apr 21 2007, 06:06 PM




