Crew-Portal Posted August 27, 2007 Share Posted August 27, 2007 Hi I have a system where mebers can rent airplanes, in virtual money and it adds or subtracts a value to mysql. How Do I make it do this? Like I already know how to make it write but I dont want the values to be overwritten I want them to be added! like if the original mysql value was 5 and I wanted to add 6 it would say 11 in the updated mysql table for posting I currently got: elseif ($action == 'postflight'){ if ($_POST['depart'] == NULL){ $error = $tblstart . 'Go Back And Put A Departure!' . $tblend; include_once($index); } elseif ($_POST['arrival'] == NULL){ $error = $tblstart . 'Go Back And Put An Arrival!' . $tblend; include_once($index); } elseif ($_POST['distance'] == NULL){ $error = $tblstart . 'Go Back And Put A Distance!' . $tblend; include_once($index); } elseif (!valid_depart($_POST['depart'])){ $error = $tblstart . 'The Departure You Entered Is Invalid!' . $tblend; include_once($index); } elseif (!valid_arrival($_POST['arrival'])){ $error = $tblstart . 'The Arrival You Entered Is Invalid!' . $tblend; include_once($index); } elseif (!valid_distance($_POST['distance'])){ $error = $tblstart . 'The Distance You Entered Is Invalid!' . $tblend; include_once($index); } else { $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $plane = $_POST['plane']; $time = date("'F j Y, g:i a'"); $strd = $_POST[depart]; $strd = strtoupper($strd); $stra = $_POST[arrival]; $stra = strtoupper($stra); $money = round($_POST[distance] + $_POST[distance] / 0.476, 2); $money2 = '$'; $money_main = '' . $money2 . '' . $money . ''; $sql="INSERT INTO flights (PilotName, FlightDate, AircraftName, NbrPassengers, CargoWeight, DepartureIcaoName, ArrivalIcaoName, TotalDistance, TotalBlockTime, money) VALUES ('CMX-$valid_user', $time, '$_POST[plane]', '$passengersrand', '$cargorand Lbs', '$strd', '$stra', '$_POST[distance] NM', '$_POST[hour]:$_POST[minute]', '$money_main')"; $error = $tblstart . 'Flight Sucessfully Posted!' . $tblend; include_once($index); $result = @mysql_query($sql,$connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); } but this code makes a new entry every time... How would I make it so it looked for the logged in user which variable is $valid_user add the inforation into distance like the previous distance stays but the new distance gets added in! Quote Link to comment https://forums.phpfreaks.com/topic/66840-solved-how-to-add-to-mysql/ Share on other sites More sharing options...
uwannadonkey Posted August 27, 2007 Share Posted August 27, 2007 do a simple query, like this: mysql_query("UPDATE `tablename` SET plane=plane+(5) WHERE id=$valid_user"); i hope that helps this line is why theres a new entry EVERY time $sql="INSERT INTO flights (PilotName, FlightDate, AircraftName, NbrPassengers, CargoWeight, DepartureIcaoName, ArrivalIcaoName, TotalDistance, TotalBlockTime, money) VALUES ('CMX-$valid_user', $time, '$_POST[plane]', '$passengersrand', '$cargorand Lbs', '$strd', '$stra', '$_POST[distance] NM', '$_POST[hour]:$_POST[minute]', '$money_main')"; $error = $tblstart . 'Flight Sucessfully Posted!' . $tblend; include_once($index); it looks like the code is made to store EACH flight, seperately, if you wish to change it, try first checking if the valid user had a row already, and if not, then insert, if he does, t hen used the mysql query i gave you Quote Link to comment https://forums.phpfreaks.com/topic/66840-solved-how-to-add-to-mysql/#findComment-335066 Share on other sites More sharing options...
Crew-Portal Posted August 27, 2007 Author Share Posted August 27, 2007 Thank you it does! TOPIC SOLVED!!! Quote Link to comment https://forums.phpfreaks.com/topic/66840-solved-how-to-add-to-mysql/#findComment-335070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.