FirefoxRocks 0 Report post Posted April 21, 2007 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 Xisto's services (and it makes it easier ). I have a database setup with 1 table to hold user data and I have the login system setup properly as well as the registration form (obviously).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: <?phprequire("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 13Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/portal/public_html/game/head.php on line 18Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/portal/public_html/game/head.php on line 23I 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. Share this post Link to post Share on other sites
pyost 0 Report post Posted April 21, 2007 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. Share this post Link to post Share on other sites
FirefoxRocks 0 Report post Posted April 21, 2007 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! :ph34r:Topic solved. Share this post Link to post Share on other sites