Hi, I am currently working on a web application for travel budgeting. I have managed to get it to insert values into my database from a form, which puts information about how much money has been spent on each category (i.e. Food, travel, entertainment, etc). However, I don’t know how to get the database to update the values in the database fields each time the user enters a new value. By update, I mean add the numbers in the form to the total of each category currently in the database.
so far this is my PHP to insert the data into the database table.
[php]if(isset($_POST[‘addinfo_button’])){
$Food = $_POST[‘food’];
$Transport = $_POST[‘transport’];
$Accom = $_POST[‘accomodation’];
$Entertain = $_POST[‘entertainment’];
$Souvenir = $_POST[‘souvenirs’];
$Misc = $_POST[‘miscellaneous’];
$Date = date(“Y-m-d”);
$Trip_id;
$sql = “SELECT * FROM trips WHERE id =$user_id_session AND date1 <= ‘$Date’ && date2 >= ‘$Date’”;
$records = mysql_query($sql);
while($trip=mysql_fetch_assoc($records)){
$Trip_id = $trip[‘trip_id’];
}
$foreignkey = $user_info[‘id’];
$sql = $con->query("INSERT INTO todays_spend (food, transport, accomodation, entertainment, souvenirs, miscellaneous,date, trip_id, id)Values('{$Food}', '{$Transport}', '{$Accom}', '{$Entertain}','{$Souvenir}', '{$Misc}','{$Date}','{$Trip_id}','{$foreignkey}')");
header('Location: budgetbuddy.php');
}[/php]
And this is what I have tried for updating it, but doesn’t work:
[php]$sql = $con->query(“UPDATE todays_spend SET food= ‘food+$Food’ transport= ‘transport+$Transport’, accomodation = ‘accomodation+$Accom’, entertainment = entertainment+$Entertain, souvenirs = ‘souvenirs+$Souvenir’, miscellaneous = ‘miscellaneous+$Misc’,date = ‘$Date’, trip_id=’$Trip_id’, id =’$foreignkey’ WHERE trip_id = $Trip_id” );[/php]