My problem is, I need to refresh the page by itself to get some variables clean, so if the user hit refresh of the page, it doesn't re-run the script and to prevent double actions...
But I have already a header.php and it gives me back this error:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Desirelist\updateBudget.php:41) in C:\xampp\htdocs\Desirelist\updateBudget.php on line 46
This is the code:
Code: Select all
<?php
include_once 'connect.php';
session_start();
include 'header.php';
if (isset($_SESSION['user']))
{
$user=$_SESSION['user'];
}
else
{
echo "<br><br> There is no logged in account. Please <A href='login.php'>Login</a><br>";
exit;
}
if ($_POST['amount'])
{
$amount=$_POST['amount'];
}
if ($_POST['operation'])
{
$operation=$_POST['operation'];
}
$userinfo="SELECT * from account where user='$user'";
$userinfo2=mysql_query($userinfo) or die("could not get account stats!");
$userinfo3=mysql_fetch_array($userinfo2);
$money=$userinfo3['money'];
if($operation == "+")
{
$money=$money+$amount;
}
else
{
$money=$money-$amount;
}
echo "Now you have ",$money,"€<br>";
mysql_query("UPDATE account SET money=$money
WHERE user='$user'");
$page=updateBudget.php;
?>
<p align="center">
<table border="3" width="21%">
<tr>
<td>
<?php
$userinfo="SELECT * from account where user='$user'";
$userinfo2=mysql_query($userinfo) or die("could not get account stats!");
$userinfo3=mysql_fetch_array($userinfo2);
$money=$userinfo3['money'];
echo "You have ",$money,"€<br><br>";
?>
<form method ="post" action="updateBudget.php">
Type the amount to be added or subtracted here: <input type="text" name="amount"><br>
<select name="operation">
<option value="+">Add Money</option>
<option value="-">Subtract Money</option>
</select>
<br>
<p align="center"><input type="submit" value="Submit" name="submit"></td></p>
</form>
</tr>
</table></p>