ok i got this script. what it does is it access's a table. that table holds unit production details for each registered user, referencing them by the user id.
when i create a new account, the details are correct. i go to this script and it displays my unit produciton details. i click upgrade and it says upgrade successful.
it refreshes but the data has been all set to 0. why is it doing this?? when it runs it just resets the data to 0, also the users gold gets set to 0 too. i posted the code below-
<?
(!defined('')) ? die : '';
(!isset($_SESSION['user_id'])) ? redirect('index.php?mode=login') : '';
if (!isset($HTTP_POST_VARS['upgrade']))
{
$user_id=$_SESSION['user_id'];
$tresult= mysql_query("SELECT * FROM user_training
WHERE user_id = $user_id");
if ($tresult)
{
echo 'tresult successful';
}else{
echo 'tresult failed';
}
$result = mysql_query("SELECT * FROM users
WHERE user_id = $user_id");
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&" method="POST">
<input type="submit" value="Upgrade" />
<input type="hidden" name="upgrade" value="true" />
</form>';
} else {
if ($member['user_gold']>=$tmember['production_cost'])
{
$user_gold=$member['user_gold']-$tmember['production_cost'];
$nproduction_lvl=$tmember['unit_production']+1;
$nnext_lvl=$tmember['next_lvl']+1;
$ncost=$tmember['production_cost']*2;
$user_result = mysql_query("UPDATE users
SET user_gold = '".$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';
timed_redirect('index.php?mode=training', 5);
}
}
}
?>
i would be greatful if someone could point out why its doing what it is doing and tell me how to remedy it.