Welcome Guest ( Log In | Register )



 
Closed TopicStart new topic
> Php Mysql Errors, Fetching arrays
FirefoxRocks
post Apr 21 2007, 06:06 PM
Post #1


Super Member
Group Icon

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 wink.gif). 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:
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.
Go to the top of the page
 
+Quote Post
pyost
post Apr 21 2007, 09:16 PM
Post #2


Nenad Bozidarevic
Group Icon

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.
Go to the top of the page
 
+Quote Post
FirefoxRocks
post Apr 21 2007, 11:28 PM
Post #3


Super Member
Group Icon

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

Topic solved.
Go to the top of the page
 
+Quote Post

Closed TopicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL - Trouble With Bulk Insert Statements(3)
  2. Recover Tables From A MySQL .frm File(8)
  3. Mirror My MySQL Database To Another Mysql Server(4)
  4. Need Help With A PHP - MySQL Registration Script(13)
  5. [PHP + MySQL] Encrypting Data(9)
  6. MySQL Output Database Question(18)
  7. MySQL, Multiple Tables(24)
  8. PHP & MySQL: Displaying Content From A Given ID(6)
  9. Navcat For MySQL(8)
  10. Qupis : Free Cpanel Web Hosting (one Line Text Ad At Bottom)(9)
  11. Login System Using A Mysql Db(5)
  12. Mysql - So Hard(14)
  13. Errors When Installing/booting(13)
  14. I Have An Error With My Mysql Connection(7)
  15. Php And Mysql Extension Installation(0)
  1. Mysql Storage Engine Error 28(5)
  2. Mysql With My Own Server(4)
  3. Mysql And User File_priv(0)
  4. Mysql Database Management(1)
  5. Mysql Database Entry By Excel Sheets(2)
  6. Phpmyadmin Continues To Have Errors.(17)
  7. Can You Link Game Maker With Mysql/php(0)
  8. Mysql On Computer(9)
  9. How To: Display A Members/user List.(3)
  10. Any Website Provide Free Host Mysql Host?(4)
  11. Mysql Multiple Tables(1)
  12. What You Need Before You Can Create A Text-based Game..(2)
  13. New Tutorials Have Issues(2)


 



- Lo-Fi Version Time is now: 29th August 2008 - 08:25 AM