Jump to content
MakeWebGames

Negative Hospital Time Glitch


Agon

Recommended Posts

Ok,

I've added this too my hospital.php

Basically it's so a user can trade 2 credits to remove 10 minutes from the hospital time.

 

[url='hospital.php?type=hospital']Remove 10 Minutes from Hospital time - 2 Credits[/url]


if($_GET['type'] == "hospital")
{
if($ir['crystals'] <2)
{
die("You don't have enough credits!");
}
else
{
mysql_query("UPDATE users SET crystals=crystals-2 WHERE userid=$userid",$c);
mysql_query("UPDATE users SET hospital=hospital-10 WHERE userid=$userid",$c);
}
}

 

Ok, Here's my problem I am stuck on.

If a user has less than 10 minutes hospital time, it puts them into a negative time.

For example

"You are currently in hospital for -10 minutes"

Anyone know how I could fix this?

Thanks in advance.

 

Link to comment
Share on other sites

ADD

 

if($ir['hospital'] > 10)
{
echo "You cannot do this due to you only have 10 mins left!";
exit($h->endpage());
}

Also, you can make your 2 queries to one because they are updating the same table and they both have the same WHERE credentails

mysql_query("UPDATE `users` SET `crystals`=`crystals`-2,`hospital`=`hospital`-10 WHERE userid=$userid",$c);

 

Also, by looking at the code, the URL bar will be something like:

http://www.game.com/hospital.php&type=hospital which can lead to members changing the hospital to something else, so for a recode

 

echo "[url='hospital.php?type=hospital']Remove 10 Minutes from Hospital time - 2 Credits[/url]
";

if(in_array($_GET['type'], array('hospital')))
{
	if($ir['crystals'] <2)
		{
	die("You don't have enough credits!");
		}
		else
		{
			mysql_query("UPDATE users SET crystals=crystals-2 WHERE userid=$userid",$c);
			mysql_query("UPDATE users SET hospital=hospital-10 WHERE userid=$userid",$c);
		}
}
else
{
	echo "Invalid Action!";
}
Link to comment
Share on other sites

    if ( $ir['hospital'] >= 10 ) {
 if ( $ir['crystals'] < 2 )  {
die("You don't have enough credits!");
 } else {
mysql_query("UPDATE `users` SET `crystals`=`crystals`-2,`hospital`=`hospital`-10 WHERE userid=$userid",$c); 
 }
   }

Although i'd just do something like

  if ( $ir['hospital'] ) {
    $hosp_rem = ( $ir['hospital'] >= 10 ) ? 10 : $ir['hospital'] ;
mysql_query("UPDATE `users` SET `crystals` = `crystals`-2, `hospital` = `hospital` - $hosp_rem WHERE `userid` = $userid", $c);
 } else {
  die('You\'re not in hospital.'.$h->endpage());
 }
Link to comment
Share on other sites

@CrimGame

if ( $ir['hospital'] ) {

$hosp_rem = ( $ir['hospital'] >= 10 ) ? 10 : $ir['hospital'] ;

mysql_query("UPDATE `users` SET `crystals` = `crystals`-2, `hospital` = `hospital` - $hosp_rem WHERE `userid` = $userid", $c);

} else {

die('You\'re not in hospital.'.$h->endpage());

}

would allow users to go negativley into crystals as you havent checked whether they have more than 2 but i do like the use of a terney there

Link to comment
Share on other sites

Ah yeah i didn't explain it properly

if ( $_GET['type'] == 'hospital'  {
if($ir['crystals'] <2) {
die("You don't have enough credits!");
} else {
    # remove /* && */ from below
/*if ( $ir['hospital'] ) {
$hosp_rem = ( $ir['hospital'] >= 10 ) ? 10 : $ir['hospital'] ;
mysql_query("UPDATE `users` SET `crystals` = `crystals`-2, `hospital` = `hospital` - $hosp_rem WHERE `userid` = $userid", $c);
} else {
die('You\'re not in hospital.'.$h->endpage());
}*/
}
}

should work perfectly

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...