ok its almost totally working now.
sadly it is setting the users gold and the next production lvl cst to 0. not sure why it is doing that. but its upgradng the other stats which is good. any ideas as to why those stats are getting set to 0?
<?
(!defined('')) ? die : '';
(!isset($_SESSION['user_id'])) ? redirect('index.php?mode=login') : '';
if (!@isset($_GET['upgrading']))
{
$user_id=$_SESSION['user_id'];
$tresult= mysql_query("SELECT * FROM `user_training`
WHERE user_id = $user_id");
if ($train=mysql_fetch_assoc($tresult)){
$cost=$train['production_cost'];
echo " produciton cost gold is $cost";
}else{
echo 'cant set user gfold';
}
if ($tresult)
{
echo 'tresult successful';
}else{
echo 'tresult failed';
}
$result = mysql_query("SELECT * FROM `users`
WHERE user_id = '".$user_id."'");
if ($user=mysql_fetch_assoc($result)){
$user_gold=$user['user_gold'];
echo " user gold is $user_gold";
}else{
echo 'cant set user gfold';
}
if ($result)
{
echo 'result successful';
}else{
echo 'result failed';
}
echo '<table width="90%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left"><b>Unit Production</b></td>
<td align="left"><b>Next Level</b></td>
<td align="left"><b>Cost</b></td>
</tr>';
while ($tmember = mysql_fetch_assoc($tresult))
{
echo '<tr>
<td align="left">'.$tmember['unit_production'].'</td>
<td align="left">'.$tmember['next_lvl'].'</td>
<td align="left">'.$tmember['production_cost'].'</td>
</tr>';
}
echo '</table>';
echo '
<form action="index.php?mode=training&upgrading=trueamp;" method="POST">
Upgrade: <input type="submit" value="Upgrade" />
<input type="hidden" name="Upgrade" value="true" />
</form>';
} else if (@isset($_GET['upgrading'])) {
$tresult= mysql_query("SELECT * FROM `user_training`
WHERE user_id = '".$user_id."'");
$tmember = mysql_fetch_assoc($tresult)or die('an error occured in this query:'.$tresult.'. The error is: '.mysql_error()) ;
if ($cost<=$user_gold)
{
$new_user_gold=$user_gold-$cost;
echo"$new gold is $new_user_gold";
$nproduction_lvl=$tmember['unit_production']+1;
$nnext_lvl=$tmember['next_lvl']+1;
$ncost=$cost+$cost;
echo "new cost is $ncost";
$user_result = mysql_query("UPDATE `users`
SET user_gold = '".$new_user_gold."'
WHERE user_id = '".$_SESSION['user_id']."'");
$tuser_result=mysql_query("UPDATE `user_training`
SET unit_production = '".$nproduction_lvl."',
next_lvl = '".$nnext_lvl."',
production_cost = '".$ncost."'
WHERE user_id = '".$_SESSION['user_id']."'");
}else{
echo 'Not enough gold';
timed_redirect('index.php?mode=training', 5);
}
if ($user_result)
{
echo 'Upgrade Successful!';
timed_redirect('index.php?mode=training', 5);
}else{
echo 'Error Occurred1';
timed_redirect('index.php?mode=training', 5);
}
if ($tuser_result)
{
echo 'Upgrade Successfu22l!';
timed_redirect('index.php?mode=training', 5);
}else{
echo 'Error Occurre2d: '.$tuser_result.'. The error is: '.mysql_error();
timed_redirect('index.php?mode=training', 5);
}
}
?>