Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if($tablename=='trips')
- {
- // insert any blank dates
- $datemax = mysql_result(mysql_query("select max(date) from trips",$con),0);
- $dategiven = $_POST['date'];
- $period = new DatePeriod(
- new DateTime($datemax),
- new DateInterval('P1D'),
- new DateTime($dategiven)
- );
- foreach ($period as $date) {
- if($date->format('Y-m-d') != $dategiven AND $date->format('Y-m-d') != $datemax) {
- mysql_query("INSERT into trips (date, kms) VALUES (\"".$date->format('Y-m-d')."\",0)",$con);
- };
- }
- }
- // insert the form data
- mysql_query('DELETE FROM '.$tablename.' WHERE date = "'.$_POST['date'].'"',$con); // delete any existing data on that date to prevent multiple entries
- $col_name = ""; $newvalue = "";
- foreach ($_POST as $key=>$value) { // this creates the list for the sql insert string
- if($key!="formID")
- {
- $col_name .= $key.",";
- if ($value != '')
- {
- $newvalue .= chr(39).$value.chr(39).",";
- }
- else
- {
- $newvalue .="NULL,";
- }
- }
- }
- $col_name = substr($col_name,0,-1); $newvalue = substr($newvalue,0,-1); // removes the last comma
- $sql = "INSERT INTO $tablename ($col_name) VALUES ($newvalue)";
- if (!mysql_query($sql,$con))
- {
- die('Error: ' . mysql_error());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement