Jump to content

Help to get script to recognize errors


zelig

Recommended Posts

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 />";
}}}}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.