Jump to content

wont update


Danny620

Recommended Posts

when i click the untrain buttion nothing seems to update but everything i want echos out fine i just don't get it no error messages or anything.

 

<?php require('config.php'); ?>
<style type="text/css">
<!--
.markert {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
background-color: #CCCCCC;
border: 1px solid #333333;
color: #FF0000;
}
.buttion {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
background-color: #D79100;
border: 1px solid #FFFFFF;
color: #669900;
}
-->
</style>

<link href="css/testting.css" rel="stylesheet" type="text/css" />
<form method="post">
  <table width="612" height="449" border="0" align="center" cellpadding="0" cellspacing="0">
    <!--DWLayoutTable-->
    <tr>
      <td height="27" colspan="3" valign="top" class="top_table">Train</td>
    </tr>
    <tr>
      <td width="200" height="40" valign="top" class="table_bottom">Spear Fighter:</td>
      <td width="206" valign="top" class="table_bottom">100 <img src="images/icons/gold coins.png" alt="Gp" width="16" height="16" /></td>
      <td width="206" valign="top" class="table_bottom"><label>
        <input name="train_s" class="textfield" value="0" size="3" maxlength="4" id="train_s" />
        You have: <?php echo $user[units];
?></label></td>
    </tr>
    <tr>
      <td height="40" valign="top" class="table_bottom">Swordsman:</td>
      <td valign="top" class="table_bottom">2000 <img src="images/icons/gold coins.png" alt="Gp" width="16" height="16" /></td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top" class="table_bottom">Axeman:</td>
      <td valign="top" class="table_bottom">4000 <img src="images/icons/gold coins.png" alt="Gp" width="16" height="16" /></td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top" class="table_bottom">Assassin:</td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top" class="table_bottom">Leader:</td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top" class="table_bottom">Knight:</td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top" class="table_bottom">Cavalry:</td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top" class="table_bottom">Ranger:</td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top" class="table_bottom">Mage:</td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top" class="table_bottom">King: (MAX 1)</td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
      <td valign="top" class="table_bottom"><!--DWLayoutEmptyCell--> </td>
    </tr>
    <tr>
      <td height="38" valign="top"><!--DWLayoutEmptyCell--> </td>
      <td valign="top"><!--DWLayoutEmptyCell--> </td>
      <td valign="top"><p align="right">
          <input name="train" type="hidden" id="train" value="Train" />
          <input name="training" type="submit" class="buttiontrain" id="training" value="" />
      </p></td>
    </tr>
  </table>
</form>

<form method="post">
  <table width="612" height="105" border="0" align="center" cellpadding="0" cellspacing="0">
    <!--DWLayoutTable-->
    <tr>
      <td height="27" colspan="3" valign="top" class="top_table">Untrain</td>
    </tr>
    <tr>
      <td width="200" height="40" valign="top" class="table_bottom">Sword:</td>
      <td width="206" valign="top" class="table_bottom">50 <img src="images/icons/gold coins.png" alt="Gp" width="16" height="16" /></td>
      <td width="206" valign="top" class="table_bottom"><label>
        <input name="untrain_s" class="textfield" value="0" size="3" maxlength="4" id="untrain_s" />
        You have: <?php echo $user[units];
?></label></td>
    </tr>

    <tr>
      <td height="38" valign="top"><!--DWLayoutEmptyCell--> </td>
      <td valign="top"><!--DWLayoutEmptyCell--> </td>
      <td valign="top"><p align="right">
        <label>
        <input type="submit" name="untrain" id="untrain" value="untrain" />
        </label>
      </p></td>
    </tr>
  </table>
</form>
<?php
//now for the PHP part
//first if train button is pressed
if ($_POST[train]) {
$train_s = (int) strip_tags(addslashes($_POST[train_s])); //number of soldiers trained

//we check if it is numeric and positive
if (!is_numeric($train_s)) { die("Wrong input!"); }
if ($train_s < 0) { die("Wrong input!"); }

//we check if we have enough money
$train_money = $train_s * 100;
if ($user[money] < $train_money) { die("Not enough money to train so many units!"); }

//if script got it to this point it was all ok so we can update
$q = "UPDATE test SET money=money-'$train_money', units=units+'$train_s' WHERE id='$user[id]'";
$r = mysqli_query($dbc, $q);
$url = 'trainingground.php'; // Define the URL:
		ob_end_clean(); // Delete the buffer.
		header("Location: $url");
		exit(); // Quit the script.
}

//we now make script which will run if we press Untrain button
if ($_POST[untrain]) {
$untrain_s = strip_tags(addslashes($_POST[untrain_s])); //number of soldiers trained
echo $untrain_s;
//we check if it is numeric and positive
if (!is_numeric($untrain_s)) { die("Wrong input!"); }
if ($untrain_s < 0) { die("Wrong input!"); }

//we check if user has enough units to untrain
if ($user[units] < $untrain_s) { die("You cannot untrain so many units!"); }

//if script got it to this point it was all ok so we can update, but first calculate amount of gained money
$gain_money = $untrain_s * 50;
echo "<br /> $gain_money";
echo "<br /> $user[id]";
//we update, so we add money gained because of untraining units, and change number of units
$q = "UPDATE test SET money=money+'$gain_money', units=units-'$train_s' WHERE id='$user[id]'";
$r = mysqli_query($dbc, $q);
//$url = 'trainingground.php'; // Define the URL:
		//ob_end_clean(); // Delete the buffer.
		//header("Location: $url");
		//exit(); // Quit the script.

}
?>
<?php
echo "<pre>";
echo "POST:";
print_r($_POST);
echo "</pre>";
?>

Link to comment
https://forums.phpfreaks.com/topic/171842-wont-update/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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