|
|
|
|
![]() ![]() |
Apr 21 2007, 06:06 PM
Post
#1
|
|
|
Super Member Group: [HOSTED] Posts: 649 Joined: 12-July 06 From: Ontario, Canada Member No.: 14,464 |
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: 998 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
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: 649 Joined: 12-July 06 From: Ontario, Canada Member No.: 14,464 |
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. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 29th August 2008 - 08:25 AM |