zelig Posted February 20, 2012 Share Posted February 20, 2012 Okay, I have a script that is supposed to break if one of the errors occurs. However, it's not. I don't know if I have it coded incorrectly or what. Any help would be appreciated! Purpose of Script: The user is supposed to be able to spend "stat bonus points" to level up their stats. However, if they have 0 points, then obviously they can't spend them. If the user tries to use more points than they have, it's supposed to break too. Thanks in advance!! if (isset($_POST["statbonus"])) { include("tmpconfig.php"); $checkquery = $db->execute("SELECT * FROM `users` WHERE `id`=?", $player->id); //$rec = mysql_fetch_array($checkquery); extract($_POST); $errors = 0; $errorlist = ""; $rec = mysql_fetch_array($checkquery); extract($_POST); $errors = 0; $errorlist = ""; if (!is_numeric($stat_bonus)) { $errors++; $errorlist .= "The amount of bonus sent needs to be a whole number.<br />"; } if ($stat_bonus == "") { $errors++; $errorlist .= "The amount of bonus is required.<br />"; } if ($amount > $stat_bonus) { $errors++; $errorlist .= "You're trying to spend more stat bonus than what you have.<br />"; } if ($stat_bonus == "0") { $errors++; $errorlist .= "You need to spend more stat bonus than just zero.<br />"; } if ($errors == 0) { $query = $db->execute("UPDATE `users` SET `stat_bonus`=? WHERE `id`=?", array($player->stat_bonus - $amount, $player->id)) or die("querya failed: ". mysql_error()); if($query) $qry = $db->execute("select * from `users` where `id`=?", array($player->id)) or die("qry failed: ".mysql_error()); $rw = $qry->fetchrow(); if($qry){ $query2 = $db->execute("UPDATE `users` SET `stat_bonus`=?, $choice=$choice+$amount WHERE `id`=?", array($player->stat_bonus - $amount, $player->id)) or die("query2 failed: ". mysql_error()); if($qry){ echo("<br><br>You have successfully used your stat bonus points.<br>"); } else { echo "<font color=green><b>You have succesfully spent skill points!</b></font><br /><br />"; }}}} Quote Link to comment https://forums.phpfreaks.com/topic/257340-help-to-get-script-to-recognize-errors/ Share on other sites More sharing options...
mikosiko Posted February 20, 2012 Share Posted February 20, 2012 where did you define $stat_bonus?.... your POST variable name is statbonus Quote Link to comment https://forums.phpfreaks.com/topic/257340-help-to-get-script-to-recognize-errors/#findComment-1319045 Share on other sites More sharing options...
zelig Posted February 20, 2012 Author Share Posted February 20, 2012 Crap, I didn't. Good catch... It will be the field within the user database "stat_bonus". $stat_bonus = $player('stat_bonus') There are times when I'm going to need to call that info from the database, other times when I'm going to reference the information from the POST. Quote Link to comment https://forums.phpfreaks.com/topic/257340-help-to-get-script-to-recognize-errors/#findComment-1319049 Share on other sites More sharing options...
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.