Agon Posted May 13, 2010 Posted May 13, 2010 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. Quote
sniko Posted May 13, 2010 Posted May 13, 2010 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!"; } Quote
Zero-Affect Posted May 13, 2010 Posted May 13, 2010 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()); } Quote
Agon Posted May 13, 2010 Author Posted May 13, 2010 thanks Thanks sniko, zero, and zed for your help. Quote
sniko Posted May 14, 2010 Posted May 14, 2010 @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 Quote
Zero-Affect Posted May 14, 2010 Posted May 14, 2010 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.