• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

correcting errors in an online game (beta)

i keep getting an error on line 152 or in other words the end of the script but i cant find it:

<?php

include('connect.php');
$result = mysql_query("SELECT username, password, email, gold, hp, strength, level FROM users where username=$uid",$db);
while ($userdata = mysql_fetch_array($result, $db))
{
$username = $userdata["username"];
$passw = $userdata["password"];
$emaila = $userdata["email"];
$gold = $userdata["gold"];
$hitpoints = $userdata["hp"];
$strength = $userdata["strength"];
$level = $userdata["level"];
$pass = base64_encode($passw);
$email = base64_encode($emaila);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Antioch Conquest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE TYPE="text/css"><!--
A:link      {
color:#999999;
text-decoration:none;
      }
A:visited      {
color:#999999;
text-decoration:none;
      }
A:hover      {
color:#FFFFFF;
font-style:italic;
text-decoration:none;
      }
A:active      {
color:#FFFFFF;
text-decoration:none;
      }
      .ib{color:#000000;background-color:#ffffff;border:1px solid #333333;font-family:Geneva}
//--></STYLE>
</head>
<body bgcolor="#000000" background="images/bricks_tile.jpg" text="#FFFFFF" link="#999999" vlink="#CCCCCC" alink="#FFFFFF" bgproperties="fixed">
<div align="center">
  <table width="620" border="0" align="center">
<tr>
      <td background="/images/top.jpg"><img src="/images/corner.jpg"></td>
      <td background="/images/top.jpg" bgcolor="#000000">
      </td>
      <td background="/images/top.jpg" bgcolor="#000000"><img src="/images/corner.jpg"></td>
    </tr>
    <tr>
      <td width="2" background="/images/side.jpg" bgcolor="#000000"></td>
      <td bgcolor="#000000"> <div align="left">
          <table width="564" height="110" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
              <td width="14%">Username:</td>
              <td> <?php echo "$username"; ?>  </td>
              <td width="11%"> </td>
              <td width="12%">Email:</td>
              <td><?php echo "$email"; ?></td>
              <td><a href="edit.php?id=$id&subject=Email&uemail=$email">Change</a></td>
            </tr>
            <tr>
              <td>Hit Points:</td>
              <td width="21%"> <?php echo "$hitpoints"; ?> </td>
              <td> </td>
              <td>Password:</td>
              <td width="25%">******</td>
              <td width="17%"><a href="edit.php?id=$id&subject=Password&upass=$pass">Change</a></td>
            </tr>
            <tr>
              <td>Gold:</td>
              <td width="21%"> <?php echo "$gold"; ?> </td>
              <td> </td>
              <td> </td>
              <td width="25%"> </td>
              <td width="17%"> </td>
            </tr>
            <tr>
              <td>Level:</td>
              <td width="21%"> <?php echo "$level"; ?> </td>
              <td> </td>
              <td> </td>
              <td width="25%"> </td>
              <td width="17%"> </td>
            </tr>
            <tr>
              <td>Strength:</td>
              <td width="21%"> <?php echo "$strength"; ?> </td>
              <td> </td>
              <td> </td>
              <td width="25%"> </td>
              <td width="17%"> </td>
            </tr>
          </table>
          <br>
        </div></td>
      <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
    </tr>
    <tr>
      <td background="images/top.jpg"><img src="images/corner.jpg"></td>
      <td background="images/top.jpg" bgcolor="#000000"></td>
      <td background="images/top.jpg" bgcolor="#000000"><img src="images/corner.jpg"></td>
    </tr>
  </table>
  <br>
  <table width="640" border="0" align="center">
<tr>
      <td background="images/top.jpg"><img src="images/corner.jpg"></td>
      <td background="images/top.jpg" bgcolor="#000000"> <div align="center">
      </td>
      <td background="images/top.jpg" bgcolor="#000000"><img src="images/corner.jpg"></td>
    </tr>
    <tr>
      <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
      <td height="280" valign="top" bgcolor="#000000">
        <div align="left"></div></td>
      <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
    </tr>
    <tr>
      <td background="images/top.jpg"><img src="images/corner.jpg"></td>
      <td background="images/top.jpg" bgcolor="#000000"></td>
      <td background="images/top.jpg" bgcolor="#000000"><img src="images/corner.jpg"></td>
    </tr>
  </table>
  <p align="center"></p>
  <table width="480" height="20" border="0" align="center">
    <tr>
      <td><img src="images/corner.jpg" width="10" height="10"></td>
      <td height="5" background="images/top.jpg">
      </td>
      <td><img src="images/corner.jpg" width="10" height="10"></td>
    </tr>
    <tr>
      <td width="5" background="images/side.jpg"></td>
      <td height="10" bgcolor="#000000"> <div align="center"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><strong>Copy
          Right 2002 ©Game Coderz All Rigths Reserved</strong></font> </div></td>
      <td width="5" background="images/side.jpg"><div align="center"></div></td>
    </tr>
    <tr>
      <td><img src="images/corner.jpg" width="10" height="10"></td>
      <td height="5" background="images/top.jpg"></td>
      <td><img src="images/corner.jpg" width="10" height="10"></td>
    </tr>
  </table>
 
</div>
</body>
</html>
0
bartonjo2
Asked:
bartonjo2
  • 10
  • 9
  • 3
  • +2
1 Solution
 
girish_nairCommented:
Hi,

You are getting this error because the "}" is missing for the while loop.

BTW, I don't think you require the while loop. because there will be only one record per user.

Cheers,
Girish
0
 
VGRCommented:
agree. Turn this to an 'if' or delete the loop beginning. This way there will be no more a closing bracket missing :D
0
 
bljakCommented:
Yes yes, listen to VGR, also he has soemtimes wise things to say =D

//bljak
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
bartonjo2Author Commented:
could you show me how to rewrite it using if
0
 
VGRCommented:
<?php

include('connect.php');
$result = mysql_query("SELECT username, password, email, gold, hp, strength, level FROM users where username=$uid",$db);
if ($userdata = mysql_fetch_array($result, $db))
{
$username = $userdata["username"];
$passw = $userdata["password"];
$emaila = $userdata["email"];
$gold = $userdata["gold"];
$hitpoints = $userdata["hp"];
$strength = $userdata["strength"];
$level = $userdata["level"];
$pass = base64_encode($passw);
$email = base64_encode($emaila);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Antioch Conquest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE TYPE="text/css"><!--
A:link     {
color:#999999;
text-decoration:none;
     }
A:visited     {
color:#999999;
text-decoration:none;
     }
A:hover     {
color:#FFFFFF;
font-style:italic;
text-decoration:none;
     }
A:active     {
color:#FFFFFF;
text-decoration:none;
     }
     .ib{color:#000000;background-color:#ffffff;border:1px solid #333333;font-family:Geneva}
//--></STYLE>
</head>
<body bgcolor="#000000" background="images/bricks_tile.jpg" text="#FFFFFF" link="#999999" vlink="#CCCCCC" alink="#FFFFFF" bgproperties="fixed">
<div align="center">
 <table width="620" border="0" align="center">
<tr>
     <td background="/images/top.jpg"><img src="/images/corner.jpg"></td>
     <td background="/images/top.jpg" bgcolor="#000000">
     </td>
     <td background="/images/top.jpg" bgcolor="#000000"><img src="/images/corner.jpg"></td>
   </tr>
   <tr>
     <td width="2" background="/images/side.jpg" bgcolor="#000000"></td>
     <td bgcolor="#000000"> <div align="left">
         <table width="564" height="110" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
             <td width="14%">Username:</td>
             <td> <?php echo "$username"; ?>  </td>
             <td width="11%"> </td>
             <td width="12%">Email:</td>
             <td><?php echo "$email"; ?></td>
             <td><a href="edit.php?id=$id&subject=Email&uemail=$email">Change</a></td>
           </tr>
           <tr>
             <td>Hit Points:</td>
             <td width="21%"> <?php echo "$hitpoints"; ?> </td>
             <td> </td>
             <td>Password:</td>
             <td width="25%">******</td>
             <td width="17%"><a href="edit.php?id=$id&subject=Password&upass=$pass">Change</a></td>
           </tr>
           <tr>
             <td>Gold:</td>
             <td width="21%"> <?php echo "$gold"; ?> </td>
             <td> </td>
             <td> </td>
             <td width="25%"> </td>
             <td width="17%"> </td>
           </tr>
           <tr>
             <td>Level:</td>
             <td width="21%"> <?php echo "$level"; ?> </td>
             <td> </td>
             <td> </td>
             <td width="25%"> </td>
             <td width="17%"> </td>
           </tr>
           <tr>
             <td>Strength:</td>
             <td width="21%"> <?php echo "$strength"; ?> </td>
             <td> </td>
             <td> </td>
             <td width="25%"> </td>
             <td width="17%"> </td>
           </tr>
         </table>
         <br>
       </div></td>
     <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
   </tr>
   <tr>
     <td background="images/top.jpg"><img src="images/corner.jpg"></td>
     <td background="images/top.jpg" bgcolor="#000000"></td>
     <td background="images/top.jpg" bgcolor="#000000"><img src="images/corner.jpg"></td>
   </tr>
 </table>
 <br>
 <table width="640" border="0" align="center">
<tr>
     <td background="images/top.jpg"><img src="images/corner.jpg"></td>
     <td background="images/top.jpg" bgcolor="#000000"> <div align="center">
     </td>
     <td background="images/top.jpg" bgcolor="#000000"><img src="images/corner.jpg"></td>
   </tr>
   <tr>
     <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
     <td height="280" valign="top" bgcolor="#000000">
       <div align="left"></div></td>
     <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
   </tr>
   <tr>
     <td background="images/top.jpg"><img src="images/corner.jpg"></td>
     <td background="images/top.jpg" bgcolor="#000000"></td>
     <td background="images/top.jpg" bgcolor="#000000"><img src="images/corner.jpg"></td>
   </tr>
 </table>
 <p align="center"></p>
 <table width="480" height="20" border="0" align="center">
   <tr>
     <td><img src="images/corner.jpg" width="10" height="10"></td>
     <td height="5" background="images/top.jpg">
     </td>
     <td><img src="images/corner.jpg" width="10" height="10"></td>
   </tr>
   <tr>
     <td width="5" background="images/side.jpg"></td>
     <td height="10" bgcolor="#000000"> <div align="center"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><strong>Copy
         Right 2002 )Game Coderz All Rigths Reserved</strong></font> </div></td>
     <td width="5" background="images/side.jpg"><div align="center"></div></td>
   </tr>
   <tr>
     <td><img src="images/corner.jpg" width="10" height="10"></td>
     <td height="5" background="images/top.jpg"></td>
     <td><img src="images/corner.jpg" width="10" height="10"></td>
   </tr>
 </table>
 
</div>
</body>
</html>
<?
} else echo "failed to get result.<BR>";
?>

// NB for clarity, I recommend converting all your game with <?
and ?>
and HTML containing <?php echo $somevariable;?>

into a big

echo <<<EOS
HTML code with $somevariable inside
etc
EOS;
} else echo "failed.";
?>
0
 
bartonjo2Author Commented:
parse error on line 157
0
 
VGRCommented:
perhaps <? should be <?php, this depends on your "short_tags" settings in php.ini
0
 
bljakCommented:
VGR forgot to close brackets at line 16, so instead of ?> write smthg like } ?>
have fun

//bljak
0
 
VGRCommented:
huh ? I did not change anything.

I closed the (missing) bracket in the only place where I touched something, ie at the end  :

<?
} else echo "failed to get result.<BR>";
?>



please note that the // comment and following lines should not be in the script code ;-)
0
 
bartonjo2Author Commented:

Warning: Supplied argument is not a valid MySQL result resource in C:\apache\htdocs\game\play.php on line 5
failed to get result :

<?php

include('connect.php');
$result = mysql_query("SELECT username, password, email, gold, hp, strength, level FROM

users where username=$uid",$db);
if ($userdata = mysql_fetch_array($result, $db))
{
$username = $userdata["username"];
$passw = $userdata["password"];
$emaila = $userdata["email"];
$gold = $userdata["gold"];
$hitpoints = $userdata["hp"];
$strength = $userdata["strength"];
$level = $userdata["level"];
$pass = base64_encode($passw);
$email = base64_encode($emaila);
echo <<<EOS


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Antioch Conquest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE TYPE="text/css"><!--
A:link     {
color:#999999;
text-decoration:none;
    }
A:visited     {
color:#999999;
text-decoration:none;
    }
A:hover     {
color:#FFFFFF;
font-style:italic;
text-decoration:none;
    }
A:active     {
color:#FFFFFF;
text-decoration:none;
    }
    .ib{color:#000000;background-color:#ffffff;border:1px solid

#333333;font-family:Geneva}
//--></STYLE>
</head>
<body bgcolor="#000000" background="images/bricks_tile.jpg" text="#FFFFFF"

link="#999999" vlink="#CCCCCC" alink="#FFFFFF" bgproperties="fixed">
<div align="center">
<table width="620" border="0" align="center">
<tr>
    <td background="/images/top.jpg"><img src="/images/corner.jpg"></td>
    <td background="/images/top.jpg" bgcolor="#000000">
    </td>
    <td background="/images/top.jpg" bgcolor="#000000"><img

src="/images/corner.jpg"></td>
  </tr>
  <tr>
    <td width="2" background="/images/side.jpg" bgcolor="#000000"></td>
    <td bgcolor="#000000"> <div align="left">
        <table width="564" height="110" border="0" align="center" cellpadding="0"

cellspacing="0">
<tr>
            <td width="14%">Username:</td>
            <td> $username  </td>
            <td width="11%"> </td>
            <td width="12%">Email:</td>
            <td>$email</td>
            <td><a href="edit.php?id=$id&subject=Email&uemail=$email">Change</a></td>
          </tr>
          <tr>
            <td>Hit Points:</td>
            <td width="21%">$hitpoints</td>
            <td> </td>
            <td>Password:</td>
            <td width="25%">******</td>
            <td width="17%"><a

href="edit.php?id=$id&subject=Password&upass=$pass">Change</a></td>
          </tr>
          <tr>
            <td>Gold:</td>
            <td width="21%">$gold</td>
            <td> </td>
            <td> </td>
            <td width="25%"> </td>
            <td width="17%"> </td>
          </tr>
          <tr>
            <td>Level:</td>
            <td width="21%">$level</td>
            <td> </td>
            <td> </td>
            <td width="25%"> </td>
            <td width="17%"> </td>
          </tr>
          <tr>
            <td>Strength:</td>
            <td width="21%">$strength</td>
            <td> </td>
            <td> </td>
            <td width="25%"> </td>
            <td width="17%"> </td>
          </tr>
        </table>
        <br>
      </div></td>
    <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
  </tr>
  <tr>
    <td background="images/top.jpg"><img src="images/corner.jpg"></td>
    <td background="images/top.jpg" bgcolor="#000000"></td>
    <td background="images/top.jpg" bgcolor="#000000"><img

src="images/corner.jpg"></td>
  </tr>
</table>
<br>
<table width="640" border="0" align="center">
<tr>
    <td background="images/top.jpg"><img src="images/corner.jpg"></td>
    <td background="images/top.jpg" bgcolor="#000000"> <div align="center">
    </td>
    <td background="images/top.jpg" bgcolor="#000000"><img

src="images/corner.jpg"></td>
  </tr>
  <tr>
    <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
    <td height="280" valign="top" bgcolor="#000000">
      <div align="left"></div></td>
    <td width="2" background="images/side.jpg" bgcolor="#000000"></td>
  </tr>
  <tr>
    <td background="images/top.jpg"><img src="images/corner.jpg"></td>
    <td background="images/top.jpg" bgcolor="#000000"></td>
    <td background="images/top.jpg" bgcolor="#000000"><img

src="images/corner.jpg"></td>
  </tr>
</table>
<p align="center"></p>
<table width="480" height="20" border="0" align="center">
  <tr>
    <td><img src="images/corner.jpg" width="10" height="10"></td>
    <td height="5" background="images/top.jpg">
    </td>
    <td><img src="images/corner.jpg" width="10" height="10"></td>
  </tr>
  <tr>
    <td width="5" background="images/side.jpg"></td>
    <td height="10" bgcolor="#000000"> <div align="center"><font size="2" face="Geneva,

Arial, Helvetica, sans-serif"><strong>Copy
        Right 2002 )Game Coderz All Rigths Reserved</strong></font> </div></td>
    <td width="5" background="images/side.jpg"><div align="center"></div></td>
  </tr>
  <tr>
    <td><img src="images/corner.jpg" width="10" height="10"></td>
    <td height="5" background="images/top.jpg"></td>
    <td><img src="images/corner.jpg" width="10" height="10"></td>
  </tr>
</table>

</div>
</body>
</html>
EOS;
} else echo "failed to get result";
?>


0
 
VGRCommented:
well, the connect failed.

I don't know what is in the include connect.php, but you should definitely add some error checking in there 8-)
0
 
bartonjo2Author Commented:
please be more specific about things
0
 
VGRCommented:
Warning: Supplied argument is not a valid MySQL result resource in C:\apache\htdocs\game\play.php on line 5

<?php

include('connect.php');
$result = mysql_query("SELECT username, password, email, gold, hp, strength, level FROM users where username=$uid",$db);
if ($userdata = mysql_fetch_array($result, $db))
{
[snip]

let's count lines :
1 : <?php
2 :
3 :include('connect.php');
4 :$result = mysql_query("SELECT username, password, email, gold, hp, strength, level FROM users where username=$uid",$db);
5 :if ($userdata = mysql_fetch_array($result, $db))

So the problem is that $result is an invalid linkID, as the error message said. This is specific enough for you ?

This means that the $result failed to return any dataset, so as there is NO ERROR CHECKING in your code, we can only guess that :
-either the query failed (perhaps because of the newlines in the string ? :D )
-either $db is an invalid database reference
-or include('connect.php') did not get it right.

THUS I suggested to write, the one in the other, something more like this :

$linkID=mysql_connect("$dbHost","$dbLogin","$dbPassword") or die ("bad connect".mysql_error());

mysql_select_db($dbName,$linkID) or die ("bad select DB yop ".mysql_error());

$query="select * from $dbTableUsers where id=$locID;";

$result=mysql_query($query,$linkID) or die ("bad query='$query' : error was ".mysql_error());

if ($res=mysql_fetch_array($result)) { // ok, found
      $locnom=$res['nom'];
      // do stuff
} // ok, trouvé
else { // not found
      // do stuff
} // if found or not
0
 
bartonjo2Author Commented:
is there a different way of doing this: $userdata = mysql_fetch_array($result, $db
0
 
VGRCommented:
i answered with my example code ....................................................................................................................................

$linkID=mysql_connect("$dbHost","$dbLogin","$dbPassword") or die ("bad connect".mysql_error());

mysql_select_db($dbName,$linkID) or die ("bad select DB yop ".mysql_error());

$query="select * from $dbTableUsers where id=$locID;";

$result=mysql_query($query,$linkID) or die ("bad query='$query' : error was ".mysql_error());

if (mysql_numrows($result)>0) {
while ($res=mysql_fetch_array($result)) { // ok, found
// process each element
} // while
} // ok, trouvi
else { // not found
  echo "no results<br>";
} // if found or not

0
 
bartonjo2Author Commented:
what i mean is there another way of selecting the users records without using fetch_array
0
 
VGRCommented:
why ?
yes, you've different ways, like using mysql_result()
0
 
girish_nairCommented:
Hi bartonjo2,

See the mysql section in the PHP manual.
:)
0
 
06jbartoCommented:
you dont need a while here:

while ($userdata = mysql_fetch_array($result, $db))
{
$username = $userdata["username"];
$passw = $userdata["password"];
$emaila = $userdata["email"];
$gold = $userdata["gold"];
$hitpoints = $userdata["hp"];
$strength = $userdata["strength"];
$level = $userdata["level"];
$pass = base64_encode($passw);
$email = base64_encode($emaila);
?>


should be
userdata = mysql_fetch_array($result, $db);

$username = $userdata["username"];
$passw = $userdata["password"];
$emaila = $userdata["email"];
$gold = $userdata["gold"];
$hitpoints = $userdata["hp"];
$strength = $userdata["strength"];
$level = $userdata["level"];
$pass = base64_encode($passw);
$email = base64_encode($emaila);
?>
0
 
bartonjo2Author Commented:
thanks!! it works now
0
 
VGRCommented:
what did this comment add over what girish_nair wrote on03/31/2003 07:25PM PST ???
0
 
girish_nairCommented:
:(

Thanks VGR for pointing it out.

I was wondering what went wrong with me
0
 
bartonjo2Author Commented:
you are right I guess I didnt pay mcuh attention to his or else I followed his comments incorrectly i will create a points for girish_nair page when i have more points
0
 
VGRCommented:
you're welcome. This happens to me all the time too ;-(
0
 
bartonjo2Author Commented:
hey moderator please delete this question, i dont want people seeing the code for my game, they can do their own work instead of steling from me

:) thanks!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 9
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now