Jump to content
MakeWebGames

Help...


CJ - Twitch

Recommended Posts

<?php
include "globals.php";
$_GET['to'] = abs((int) $_GET['to']);
if(!$_GET['to'])
{
print "Welcome to the Monorail Station.

Where would you like to travel today?
";
$q=$db->query("SELECT * FROM cities WHERE cityid != {$ir['location']} AND cityminlevel <= {$ir['level']}");
print "<table width=75% cellspacing=1 class='table'><tr style='background:gray'><th>Name</th><th>Description</th><th>Min 

Level</th><th>Cost</th><th></th></tr>";
while($r=$db->fetch_row($q))
{
print "<tr><td>{$r['cityname']}</td><td>{$r['citydesc']}</td><td>{$r['cityminlevel']}</td><td>\${$r['citycost']}</td><td><a href='monorail.php?to={$r

['cityid']}'>Go</a></td></tr>";
}
print "</table>";
}
else
{
if($ir['money'] < $r['citycost'])
{
print "You don't have enough money. You need {$r['citycost']} to travel to {$r['cityname']}";
}
else if( ((int) $_GET['to']) != $_GET['to'])
{
print "Invalid city ID";
}
else
{
$q=$db->query("SELECT * FROM cities WHERE cityid = {$_GET['to']} AND cityminlevel <= {$ir['level']}");
if(!$db->num_rows($q))
{
print "Error, this city either does not exist or you cannot go there.";
}
else
{
$db->query("UPDATE users SET money=money-{$r['citycost']},location={$_GET['to']} WHERE userid=$userid");
$r=$db->fetch_row($q);
print "Congratulations, you paid \${$r['citycost']} and travelled to {$r['cityname']} on the monorail!";
}
}
}
$h->endpage();
?>

 

[mysql]ALTER TABLE `cities` ADD `citycost` INT( 11 ) NOT NULL AFTER `cityid` ;[/mysql]

This is my script but I get this...

QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'location=2 WHERE userid=1' at line 1

Query was UPDATE users SET money=money-,location=2 WHERE userid=1

Any ideas?

Link to comment
Share on other sites

here you are it works on my game and ive made it a little more secure than what you posted up

 

<?php
include "globals.php";
$_GET['to'] = isset($_GET['to']) && is_numeric($_GET['to']) ? abs((int) $_GET['to']) : false;
if(!$_GET['to'])
{
print "Welcome to the Monorail Station.

Where would you like to travel today?
";
$q=$db->query("SELECT * FROM `cities` WHERE `cityid` != {$ir['location']} AND `cityminlevel` <= {$ir['level']}");
print "<table width=75% cellspacing=1 class='table'><tr style='background:gray'><th>Name</th><th>Description</th><th>Min 

Level</th><th>Cost</th><th></th></tr>";
while($r=$db->fetch_row($q))
{
print "<tr><td>{$r['cityname']}</td><td>{$r['citydesc']}</td><td>{$r['cityminlevel']}</td><td>\${$r['citycost']}</td><td><a href='monorail.php?to={$r

['cityid']}'>Go</a></td></tr>";
}
print "</table>";
}
else
{
if($ir['money'] < $r['citycost'])
{
print "You don't have enough money. You need {$r['citycost']} to travel to {$r['cityname']}";
}
else if( ((int) $_GET['to']) != $_GET['to'])
{
print "Invalid city ID";
}
else
{
$qq=$db->query("SELECT * FROM cities WHERE cityid = {$_GET['to']} AND cityminlevel <= {$ir['level']}");
if(!$db->num_rows($qq))
{
print "Error, this city either does not exist or you cannot go there.";
}
else
{
$r=$db->fetch_row($qq);
$db->query(sprintf("UPDATE users SET money	= money - %d, location = %d WHERE (userid = %d)", $r['citycost'], $_GET['to'], $ir['userid']));

print "Congratulations, you paid \${$r['citycost']} and travelled to {$r['cityname']} on the monorail!";
}
}
}
$h->endpage();
?>
Link to comment
Share on other sites

I got a little bored hope you don't mind...

<?php
include_once (DIRNAME(__FILE__) . '/globals.php');
# $_GET['to'] = isset($_GET['to']) && is_numeric($_GET['to']) ? abs((int) $_GET['to']) : false;
# Always wondered why people added abs((int) $var) ctype_digit will basically do a check on variables and won't output if it's actually numeric...
	$_GET['to'] = ( isset($_GET['to']) AND ctype_digit($_GET['to']) ) ? $_GET['to'] : 0 ;
      if ( empty($_GET['to']) ) {
  echo '
 Welcome to the Monorail Station.


 Where would you like to travel today?


  ';
$q = $db->query('SELECT `cityname`, `citydesc`, `cityminlevel`, `citycost`, `cityid` FROM `cities` WHERE `cityid` != '.$ir['location'].' AND `cityminlevel` <= '.$ir['level']);
  echo '
<table width="75%" cellspacing="1" class="table">
	<tr style="background:gray">
<th>Name</th>
<th>Description</th>
<th>Min Level</th>
<th>Cost</th>
<th></th>
	</tr>
  ';
         while( $r = $db->fetch_row($q) ) {
  echo '
	<tr>
<td>'.$r['cityname'].'</td>
<td>'.$r['citydesc'].'</td>
<td>'.$r['cityminlevel'].'</td>
<td>'.money_formatter($r['citycost']).'</td>
<td>[url="monorail.php?to='.$r['cityid'].'"]Go[/url]</td>
	</tr>
  ';
         }
  echo '</table>';
      } else {
/*      if ( $ir['money'] < $r['citycost'] ) {
  echo 'You don\'t have enough money. You need '.$r['citycost'].' to travel to '.$r['cityname'];
     } else
# The above is pointless unless you have predefined $r
if( ((int) $_GET['to']) != $_GET['to']) { // <= lmao
  echo 'Invalid city ID';
     } else {*/
$qq = $db->query('SELECT `citycost`, `cityname` FROM `cities` WHERE `cityid` = '.$_GET['to'].' AND `cityminlevel` <= '.$ir['level']);
    if(!$db->num_rows($qq)) {
print "Error, this city either does not exist or you cannot go there.";
    } else {
$r = $db->fetch_row($qq);
 if ( $ir['money'] < $r['citycost'] ) {
  echo 'You don\'t have enough money. You need '.$r['citycost'].' to travel to '.$r['cityname'];
 }
$db->query('UPDATE `users` SET `money`    = `money` - '.$r['citycost'].', `location` = '.$_GET['to'].' WHERE `userid` = '.$ir['userid']);
  echo 'Congratulations, you paid '.money_formatter($r['citycost']).' and travelled to '.$r['cityname'].' on the monorail!';
    }
#      }
      }
  $h->endpage();
?>

i added some notes but if that's generic MCC that not defined $r issue will be on all the generic monorail modifications, surprised no one noticed it...

Link to comment
Share on other sites

One thing... You forgot a else statement... :P It use to say you don't have enough money and still took you there... for example..

You don't have enough money. You need $100,000 to travel to TEST1Congratulations, you paid $100,000 and travelled to TEST1 on the monorail!

Fixed.

<?php
include_once (DIRNAME(__FILE__) . '/globals.php');
   # $_GET['to'] = isset($_GET['to']) && is_numeric($_GET['to']) ? abs((int) $_GET['to']) : false;
   # Always wondered why people added abs((int) $var) ctype_digit will basically do a check on variables and won't output if it's actually numeric...
       $_GET['to'] = ( isset($_GET['to']) AND ctype_digit($_GET['to']) ) ? $_GET['to'] : 0 ;
      if ( empty($_GET['to']) ) {
  echo '
 Welcome to the Monorail Station.


 Where would you like to travel today?


  ';
   $q = $db->query('SELECT `cityname`, `citydesc`, `cityminlevel`, `citycost`, `cityid` FROM `cities` WHERE `cityid` != '.$ir['location'].' AND 

`cityminlevel` <= '.$ir['level']);
  echo '
<table width="75%" cellspacing="1" class="table">
       <tr style="background:gray">
   <th>Name</th>
   <th>Description</th>
   <th>Min Level</th>
   <th>Cost</th>
   <th></th>
       </tr>
  ';
         while( $r = $db->fetch_row($q) ) {
  echo '
       <tr>
   <td>'.$r['cityname'].'</td>
   <td>'.$r['citydesc'].'</td>
   <td>'.$r['cityminlevel'].'</td>
   <td>'.money_formatter($r['citycost']).'</td>
   <td>[url="monorail.php?to='.$r['cityid'].'"]Go[/url]</td>
       </tr>
  ';
         }
  echo '</table>';
      } else {
/*      if ( $ir['money'] < $r['citycost'] ) {
  echo 'You don\'t have enough money. You need '.$r['citycost'].' to travel to '.$r['cityname'];
     } else
   # The above is pointless unless you have predefined $r
if( ((int) $_GET['to']) != $_GET['to']) { // <= lmao
  echo 'Invalid city ID';
     } else {*/
   $qq = $db->query('SELECT `citycost`, `cityname` FROM `cities` WHERE `cityid` = '.$_GET['to'].' AND `cityminlevel` <= '.$ir['level']);
    if(!$db->num_rows($qq)) {
print "Error, this city either does not exist or you cannot go there.";
    } 
     else 
    {
   $r = $db->fetch_row($qq);
 if ( $ir['money'] < $r['citycost'] ) 
 {
  echo 'You don\'t have enough money. You need '.money_formatter($r['citycost']).' to travel to '.$r['cityname'];
 }
  else
 {
   $db->query('UPDATE `users` SET `money`    = `money` - '.$r['citycost'].', `location` = '.$_GET['to'].' WHERE `userid` = '.$ir['userid']);
  echo 'Congratulations, you paid '.money_formatter($r['citycost']).' and travelled to '.$r['cityname'].' on the monorail!';
    }
         } 
      }
  $h->endpage();
?>

 

Thanks again. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...