Jump to content

Adding / subtracting time, then put it into other input boxes?


VinceGledhill

Recommended Posts

Hello people.

 

Thank you to everyone who has helped me in the past, this is a great forum full of very helpful members.

 

I am trying to put a pilots logbook application together for the members at microlightforum.com and here is the form that I have put together.

add_logbook_entry.png

 

What I would like to know is how to code the first "Auto Insert" button so that it takes the time from the variables $takeoff_hr and $takeoff_min and $landing_hr, $landing_min

 

I would like the time difference from taking off to landing putting in the "ws_captain_hrs" box and the "ws_captain_min" box.  Therefore if someone took off at 12.30 and landed at 13.50 the "ws_captain_hrs" box should read "1" and the "ws_captain_min" box should read "20"

 

The idea behind this is that it makes it easier for the user to only have to insert take off time and landing time, then click the appropriate button to put the data into the box. 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

$host = 'localhost';
$usr = "vinny";
$password = 'thepassword';
$db_name = 'logbook';

$date = $_POST['date'];
$type = $_POST['type'];
$reg_01 = $_POST['reg_01'];
$reg_02 = $_POST['reg_02'];
$captain = $_POST['captain'];
$passenger = $_POST['passenger'];
$where_01 = $_POST['where_01'];
$where_02 = $_POST['where_02'];
$takeoff_hr = $_POST['takeoff_hr'];
$takeoff_min = $_POST['takeoff_min'];
$landing_hr = $_POST['landing_hr'];
$landing_min = $_POST['landing_min'];
$ws_captain_hrs = $_POST['ws_captain_hrs'];
$ws_captain_min = $_POST['ws_captain_min'];
$ws_student_hrs = $_POST['ws_student_hrs'];
$ws_student_min = $_POST['ws_student_min'];
$three_captain_hrs = $_POST['three_captain_hrs']; 
$three_captain_min = $_POST['three_captain_min'];
$three_student_hrs = $_POST['three_student_hrs'];
$three_student_min = $_POST['three_student_min'];
$passenger_hrs = $_POST['passenger_hrs'];
$passenger_min = $_POST['passenger_min'];
$remarks = $_POST['remarks'];


$errorstring = ""; // default value of errorstring

if(isset($_POST['save_flight'])) {
// Validate all the code inputs that are required fields
if ($date =="")
$errorstring = $errorstring. "Date<br>";
if ($type =="")
$errorstring = $errorstring. "Aircraft Type<br>";
if ($reg_01 =="")
$errorstring = $errorstring. "Reg Prefix<br>"; 
if ($reg_02 =="")
$errorstring = $errorstring. "Registration Mark<br>";
if ($captain =="")
$errorstring = $errorstring. "Captain<br>";
if ($where_01 =="")
$errorstring = $errorstring. "Flight From<br>";
if ($where_02 =="")
$errorstring = $errorstring. "Flight To<br>";
if ($takeoff_hr =="")
$errorstring = $errorstring. "Takeoff Hours<br>";
if ($takeoff_min =="") 
$errorstring = $errorstring. "Takeoff Minutes<br>";
if ($landing_hr =="")
$errorstring = $errorstring. "Landing Hours<br>";
if ($landing_min =="") 
$errorstring = $errorstring. "Landing Minutes<br>";


// does the errorstring = "nothing"?
if ($errorstring !="")
echo "You have not put anything in the following fields: <br><br> $errorstring";
//echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\"";
//die ("Please try again, ensuring that you fill out all the fields!");
else 
{
//echo "Your data has been saved";
//connect to database
mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error());
mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error());

$insert_query = "INSERT INTO pilots_logbook (date, type, reg_01, reg_02, captain, passenger, where_01, where_02, takeoff_hr, takeoff_min, landing_hr, landing_min, ws_captain_hrs, ws_captain_min, ws_student_hrs, ws_student_min, three_captain_hrs, three_captain_min, three_student_hrs, three_student_min, passenger_hrs, passenger_min, remarks) VALUES ('$date', '$type', '$reg_01', '$reg_02', '$captain', '$passenger', '$where_01', '$where_02', '$takeoff_hr', '$takeoff_min', '$landing_hr', '$landing_min', '$ws_captain_hrs', '$ws_captain_min', '$ws_student_hrs', '$ws_student_min', '$three_captain_hrs', '$three_captain_min', '$three_student_hrs', '$three_student_min','$passenger_hrs', '$passenger_min', '$remarks')";
$insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query);

$id = mysql_insert_id();

echo "Thank you, Your logbook entry has been saved.";
}
}

?>
<p>Use this form to add an entry to your logbook.</p>
<form name = "form1" method ="post" action="">
<table width="650" border="1" cellspacing="0" cellpadding="5">
  <tr>
    <td>Required *</td>
    <td> </td>
    <td>This Format Only</td>
  </tr>
  <tr>
    <td width="180">Date *</td>
    <td width="300">
      <input type="text" name="date" id="date" size = "25"/>
    </label>
     <input type="submit" name="today" id="today" value="Add Today" /></td>
    <td width="170">YYYY-MM-DD</td>
  </tr>
  <tr>
    <td>Aircraft Type *</td>
    <td><input type="text" name="type" id="type" size = "40" /></td>
    <td>E.G. Quantum</td>
  </tr>
  <tr>
    <td>Reg Number *</td>
    <td><input type="text" name="reg_01" id="reg_01" size = "5" /> 
      - 
      <input type="text" name="reg_02" id="reg_02" size = "15"/></td>
    <td>G - ABCD</td>
  </tr>
  <tr>
    <td>Captain *</td>
    <td><input type="text" name="captain" id="captain" size = "40" /></td>
    <td>Name of Captain</td>
  </tr>
  <tr>
    <td>Passenger or Student</td>
    <td><input type="text" name="passenger" id="passenger" size = "40" /></td>
    <td>Were you? P or S</td>
  </tr>
  <tr>
    <td>Flight From *</td>
    <td><input type="text" name="where_01" id="where_01" size = "40" /></td>
    <td>Take off Airfield</td>
  </tr>
  <tr>
    <td>Flight To *</td>
    <td><input type="text" name="where_02" id="where_02" size = "40" /></td>
    <td>Landing Airfield</td>
  </tr>
  <tr>
    <td>Takeoff GMT *</td>
    <td><label>Hr 
        <input type="text" name="takeoff_hr" id="takeoff_hr" size = "10" />
        Min
        <input type="text" name="takeoff_min" id="takeoff_min" size="10"/>
    </label></td>
    <td>24 Hr Format Only</td>
  </tr>
  <tr>
    <td>Landing GMT *</td>
    <td><label>Hr 
        <input type="text" name="landing_hr" id="landing_hr" size="10" />
        Min
        <input type="text" name="landing_min" id="landing_min" size="10" />
    </label></td>
    <td>24 Hr Format Only</td>
  </tr>
  <tr>
    <td>Captain Weighshift</td>
    <td><label>Hrs 
      <input type="text" name="ws_captain_hrs" id="ws_captain_hrs" size = "10"/></label>
      <label>Min
        <input type="text" name="ws_captain_min" id="ws_captain_min" size = "10" />
        <input type="submit" name="autofill_ws_captain" id="autofill_ws_captain" value="Auto Insert" />
        <!--This is the button I would like to take the time from the take off and put it into the captain weightshift hrs and min boxes -->
        
        
    </label></td>
    <td>Button works it out and inserts it here</td>
  </tr>
  <tr>
    <td>Student Weightshift</td>
    <td><label>Hrs 
      <input type="text" name="ws_student_hrs" id="ws_student_hrs" size = "10"/></label>
      <label>Min
        <input type="text" name="ws_student_min" id="ws_student_min" size="10" />
        <input type="submit" name="autofill_ws_student" id="autofill_ws_student" value="Auto Insert" />
      </label></td>
    <td>Button works it out and inserts it here</td>
  </tr>
  <tr>
    <td>Captain 3 Axis</td>
    <td><label>Hrs
      <input type="text" name="three_captain_hrs" id="three_captain_hrs" size = "10"/>
    </label>
      <label>Min
        <input type="text" name="three_captain_min" id="three_captain_min" size = "10" />
        <input type="submit" name="autofill_3_captain" id="autofill_3_captain" value="Auto Insert" />
    </label></td>
    <td>Button works it out and inserts it here</td>
  </tr>
  <tr>
    <td>Student  3 Axis</td>
    <td><label>Hrs
      <input type="text" name="three_student_hrs" id="three_student_hrs" size = "10"/>
    </label>
      <label>Min
        <input type="text" name="three_student_min" id="three_student_min" size = "10" />
        <input type="submit" name="autofill_3_student" id="autofill_3_student" value="Auto Insert" />
    </label></td>
    <td>Button works it out and inserts it here</td>
  </tr>
  <tr>
    <td>Passenger Interest Only</td>
    <td>Hrs
    <input type="text" name="passenger_hrs" id="passenger_hrs" size="10"/>
    Min
    <input type="text" name="passenger_min" id="passenger_min" size="10"/>
    <input type="submit" name="passenger_button" id="passenger_button" value="Auto Insert" /></td>
    <td>Button works it out and inserts it here</td>
  </tr>
  <tr>
    <td>Remarks</td>
    <td><textarea name="remarks" id="remarks" cols="45" rows="5"></textarea></td>
    <td>Went to get microlight forum cup from XYZ airfield. Maximum 500 characters</td>
  </tr>
  <tr>
    <td><input type="submit" name="save_flight" id="save_flight" value="Save Flight" /></td>
    <td><input type="submit" name="reset" id="reset" value="Reset Form" /></td>
    <td> </td>
  </tr>
</table>
<p> </p>
<p> </p>
</body>
</html>

 

Link to comment
Share on other sites

You're pretty much limited as to how you can do this unless you want to make use of javascript.  You would need to put in a "value" field for each input box so it could retain any input that was made prior to the use of a button, like this:

 

<input type="text" name="takeoff_hr" id="takeoff_hr" size="10" value="<?php echo $takeoff_hr; ?>" />

 

You'll notice that the reset button no longer works, since anything entered in a field is being passed through POST when you press "Reset Form".  Adding a header redirect to the top of the page fixes this.

 

Here's all of the code:

 

<?php
if(isset($_POST['reset'])) {
header('Location: index.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

$host = 'localhost';
$usr = "vinny";
$password = 'thepassword';
$db_name = 'logbook';

$date = $_POST['date'];
$type = $_POST['type'];
$reg_01 = $_POST['reg_01'];
$reg_02 = $_POST['reg_02'];
$captain = $_POST['captain'];
$passenger = $_POST['passenger'];
$where_01 = $_POST['where_01'];
$where_02 = $_POST['where_02'];
$takeoff_hr = $_POST['takeoff_hr'];
$takeoff_min = $_POST['takeoff_min'];
$landing_hr = $_POST['landing_hr'];
$landing_min = $_POST['landing_min'];
$ws_captain_hrs = $_POST['ws_captain_hrs'];
$ws_captain_min = $_POST['ws_captain_min'];
$ws_student_hrs = $_POST['ws_student_hrs'];
$ws_student_min = $_POST['ws_student_min'];
$three_captain_hrs = $_POST['three_captain_hrs']; 
$three_captain_min = $_POST['three_captain_min'];
$three_student_hrs = $_POST['three_student_hrs'];
$three_student_min = $_POST['three_student_min'];
$passenger_hrs = $_POST['passenger_hrs'];
$passenger_min = $_POST['passenger_min'];
$remarks = $_POST['remarks'];

if(isset($_POST['autofill_ws_captain']) && isset($_POST['takeoff_hr']) && isset($_POST['takeoff_min']) && isset($_POST['landing_hr']) && isset($_POST['landing_min'])) {
$ws_captain_hrs = $takeoff_hr - $landing_hr;
$ws_captain_hrs = str_replace("-", "", $ws_captain_hrs);
if(strlen($ws_captain_hrs) == "1") {
	$ws_captain_hrs = "0".$ws_captain_hrs;
}
$ws_captain_min = $takeoff_min - $landing_min;
$ws_captain_min = str_replace("-", "", $ws_captain_min);
if(strlen($ws_captain_min) == "1") {
	$ws_captain_min = "0".$ws_captain_min;
}
} elseif(isset($_POST['autofill_ws_student'])) {
// Calculate ws_student fields
} elseif(isset($_POST['autofill_3_captain'])) {
// Calculate 3_captain fields
} elseif(isset($_POST['autofill_3_student'])) {
// Calculate 3_student fields
} elseif(isset($_POST['today'])) {
$date = date("Y-m-d");
}

$errorstring = ""; // default value of errorstring

if(isset($_POST['save_flight'])) {
// Validate all the code inputs that are required fields
if ($date =="")
$errorstring = $errorstring. "Date<br>";
if ($type =="")
$errorstring = $errorstring. "Aircraft Type<br>";
if ($reg_01 =="")
$errorstring = $errorstring. "Reg Prefix<br>"; 
if ($reg_02 =="")
$errorstring = $errorstring. "Registration Mark<br>";
if ($captain =="")
$errorstring = $errorstring. "Captain<br>";
if ($where_01 =="")
$errorstring = $errorstring. "Flight From<br>";
if ($where_02 =="")
$errorstring = $errorstring. "Flight To<br>";
if ($takeoff_hr =="")
$errorstring = $errorstring. "Takeoff Hours<br>";
if ($takeoff_min =="") 
$errorstring = $errorstring. "Takeoff Minutes<br>";
if ($landing_hr =="")
$errorstring = $errorstring. "Landing Hours<br>";
if ($landing_min =="") 
$errorstring = $errorstring. "Landing Minutes<br>";


// does the errorstring = "nothing"?
if ($errorstring !="")
echo "You have not put anything in the following fields: <br><br> $errorstring";
//echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\"";
//die ("Please try again, ensuring that you fill out all the fields!");
elseif(isset($_POST['save_flight']))
{
//echo "Your data has been saved";
//connect to database
mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error());
mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error());

$insert_query = "INSERT INTO pilots_logbook (date, type, reg_01, reg_02, captain, passenger, where_01, where_02, takeoff_hr, takeoff_min, landing_hr, landing_min, ws_captain_hrs, ws_captain_min, ws_student_hrs, ws_student_min, three_captain_hrs, three_captain_min, three_student_hrs, three_student_min, passenger_hrs, passenger_min, remarks) VALUES ('$date', '$type', '$reg_01', '$reg_02', '$captain', '$passenger', '$where_01', '$where_02', '$takeoff_hr', '$takeoff_min', '$landing_hr', '$landing_min', '$ws_captain_hrs', '$ws_captain_min', '$ws_student_hrs', '$ws_student_min', '$three_captain_hrs', '$three_captain_min', '$three_student_hrs', '$three_student_min','$passenger_hrs', '$passenger_min', '$remarks')";
$insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query);

$id = mysql_insert_id();

echo "Thank you, Your logbook entry has been saved.";
}
}

?>
<p>Use this form to add an entry to your logbook.</p>
<form name="form1" method="post" action="index.php">
<table width="650" border="1" cellspacing="0" cellpadding="5">
<tr>
<td>Required *</td>
<td> </td>
<td>This Format Only</td>
</tr>
<tr>
<td width="180">Date *</td>
<td width="300">
	<input type="text" name="date" id="date" size="25"/ value="<?php echo $date; ?>" />
	<input type="submit" name="today" id="today" value="Add Today" />
</td>
<td width="170">YYYY-MM-DD</td>
</tr>
<tr>
<td>Aircraft Type *</td>
<td><input type="text" name="type" id="type" size="40" / value="<?php echo $type; ?>" /></td>
<td>E.G. Quantum</td>
</tr>
<tr>
<td>Reg Number *</td>
<td><input type="text" name="reg_01" id="reg_01" size="5" value="<?php echo $reg_01; ?>" /> - <input type="text" name="reg_02" id="reg_02" size="15" value="<?php echo $reg_02; ?>" /></td>
<td>G - ABCD</td>
</tr>
<tr>
<td>Captain *</td>
<td><input type="text" name="captain" id="captain" size="40" value="<?php echo $captain; ?>" /></td>
<td>Name of Captain</td>
</tr>
<tr>
<td>Passenger or Student</td>
<td><input type="text" name="passenger" id="passenger" size="40" value="<?php echo $passenger; ?>" /></td>
<td>Were you? P or S</td>
</tr>
<tr>
<td>Flight From *</td>
<td><input type="text" name="where_01" id="where_01" size="40" value="<?php echo $where_01; ?>" /></td>
<td>Take off Airfield</td>
</tr>
<tr>
<td>Flight To *</td>
<td><input type="text" name="where_02" id="where_02" size="40" value="<?php echo $where_02; ?>" /></td>
<td>Landing Airfield</td>
</tr>
<tr>
<td>Takeoff GMT *</td>
<td>
	<label>
		Hr <input type="text" name="takeoff_hr" id="takeoff_hr" size="10" value="<?php echo $takeoff_hr; ?>" />
		Min <input type="text" name="takeoff_min" id="takeoff_min" size="10" value="<?php echo $takeoff_min; ?>" />
	</label>
</td>
<td>24 Hr Format Only</td>
</tr>
<tr>
<td>Landing GMT *</td>
<td>
	<label>
		Hr <input type="text" name="landing_hr" id="landing_hr" size="10" value="<?php echo $landing_hr; ?>" />
		Min <input type="text" name="landing_min" id="landing_min" size="10" value="<?php echo $landing_min; ?>" />
	</label>
</td>
<td>24 Hr Format Only</td>
</tr>
<tr>
<td>Captain Weighshift</td>
<td>
	<label>Hrs <input type="text" name="ws_captain_hrs" id="ws_captain_hrs" size="10" value="<?php echo $ws_captain_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="ws_captain_min" id="ws_captain_min" size="10" value="<?php echo $ws_captain_min; ?>" />
		<input type="submit" name="autofill_ws_captain" id="autofill_ws_captain" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Student Weightshift</td>
<td>
	<label>Hrs <input type="text" name="ws_student_hrs" id="ws_student_hrs" size="10" value="<?php echo $ws_student_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="ws_student_min" id="ws_student_min" size="10" value="<?php echo $ws_student_min; ?>" />
		<input type="submit" name="autofill_ws_student" id="autofill_ws_student" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Captain 3 Axis</td>
<td>
	<label>Hrs <input type="text" name="three_captain_hrs" id="three_captain_hrs" size="10" value="<?php echo $three_captain_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="three_captain_min" id="three_captain_min" size="10" value="<?php echo $three_captain_min; ?>" />
		<input type="submit" name="autofill_3_captain" id="autofill_3_captain" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Student 3 Axis</td>
<td>
	<label>Hrs <input type="text" name="three_student_hrs" id="three_student_hrs" size="10" value="<?php echo $three_student_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="three_student_min" id="three_student_min" size="10" value="<?php echo $three_student_min; ?>" />
		<input type="submit" name="autofill_3_student" id="autofill_3_student" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Passenger Interest Only</td>
<td>
	Hrs <input type="text" name="passenger_hrs" id="passenger_hrs" size="10" value="<?php echo $passenger_hrs; ?>" />
	Min <input type="text" name="passenger_min" id="passenger_min" size="10" value="<?php echo $passenger_min; ?>" />
	<input type="submit" name="passenger_button" id="passenger_button" value="Auto Insert" />
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Remarks</td>
<td><textarea name="remarks" id="remarks" cols="45" rows="5"><?php echo $remarks; ?></textarea></td>
<td>Went to get microlight forum cup from XYZ airfield. Maximum 500 characters</td>
</tr>
<tr>
<td><input type="submit" name="save_flight" id="save_flight" value="Save Flight" /></td>
<td><input type="submit" name="reset" id="reset" value="Reset Form" /></td>
<td> </td>
</tr>
</table>
<p> </p>
<p> </p>
</body>
</html>

 

Let me know if you have any questions.

 

Hope this helps! :D

Link to comment
Share on other sites

Here's my updated code but I've messed it all up and all I get is a blank screen now :-(

<?php
if(isset($_POST['reset'])) {
header('Location: index1.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

$host = 'localhost';
$usr = "vinny";
$password = 'thepassword';
$db_name = 'logbook';

$today = date("Y-m-d");

$date = $_POST['date'];
$type = $_POST['type'];
$reg_01 = $_POST['reg_01'];
$reg_02 = $_POST['reg_02'];
$captain = $_POST['captain'];
$passenger = $_POST['passenger'];
$where_01 = $_POST['where_01'];
$where_02 = $_POST['where_02'];
$takeoff_hr = $_POST['takeoff_hr'];
$takeoff_min = $_POST['takeoff_min'];
$landing_hr = $_POST['landing_hr'];
$landing_min = $_POST['landing_min'];
$ws_captain_hrs = $_POST['ws_captain_hrs'];
$ws_captain_min = $_POST['ws_captain_min'];
$ws_student_hrs = $_POST['ws_student_hrs'];
$ws_student_min = $_POST['ws_student_min'];
$three_captain_hrs = $_POST['three_captain_hrs']; 
$three_captain_min = $_POST['three_captain_min'];
$three_student_hrs = $_POST['three_student_hrs'];
$three_student_min = $_POST['three_student_min'];
$passenger_hrs = $_POST['passenger_hrs'];
$passenger_min = $_POST['passenger_min'];
$remarks = $_POST['remarks'];

if(isset($_POST['autofill_ws_captain']) && isset($_POST['takeoff_hr']) && isset($_POST['takeoff_min']) && isset($_POST['landing_hr']) && isset($_POST['landing_min'])) {
$ws_captain_hrs = $takeoff_hr - $landing_hr;
$ws_captain_hrs = str_replace("-", "", $ws_captain_hrs);
if(strlen($ws_captain_hrs) == "1") {
	$ws_captain_hrs = "0".$ws_captain_hrs;
}
$ws_captain_min = $takeoff_min - $landing_min;
$ws_captain_min = str_replace("-", "", $ws_captain_min);
if(strlen($ws_captain_min) == "1") {
	$ws_captain_min = "0".$ws_captain_min;
}
} 
if(isset($_POST['autofill_ws_student'])) && isset($_POST['takeoff_hr']) && isset($_POST['takeoff_min']) && isset($_POST['landing_hr']) && isset($_POST['landing_min'])) {
$ws_student_hrs = $takeoff_hr - $landing_hr;
$ws_student_hrs = str_replace("-", "", $ws_student_hrs);
if(strlen($ws_student_hrs) == "1") {
	$ws_student_hrs = "0".$ws_student_hrs;
}
$ws_student_min = $takeoff_min - $landing_min;
$ws_student_min = str_replace("-", "", $ws_student_min);
if(strlen($ws_student_min) == "1") {
	$ws_student_min = "0".$ws_student_min;
}
elseif(isset($_POST['autofill_3_captain'])) {
// Calculate 3_captain fields
} 
elseif(isset($_POST['autofill_3_student'])) {
// Calculate 3_student fields
} 
elseif(isset($_POST['today'])) {
$date = date("Y-m-d");
}

$errorstring = ""; // default value of errorstring

if(isset($_POST['save_flight'])) {
// Validate all the code inputs that are required fields
if ($date =="")
$errorstring = $errorstring. "Date<br>";
if ($type =="")
$errorstring = $errorstring. "Aircraft Type<br>";
if ($reg_01 =="")
$errorstring = $errorstring. "Reg Prefix<br>"; 
if ($reg_02 =="")
$errorstring = $errorstring. "Registration Mark<br>";
if ($captain =="")
$errorstring = $errorstring. "Captain<br>";
if ($where_01 =="")
$errorstring = $errorstring. "Flight From<br>";
if ($where_02 =="")
$errorstring = $errorstring. "Flight To<br>";
if ($takeoff_hr =="")
$errorstring = $errorstring. "Takeoff Hours<br>";
if ($takeoff_min =="") 
$errorstring = $errorstring. "Takeoff Minutes<br>";
if ($landing_hr =="")
$errorstring = $errorstring. "Landing Hours<br>";
if ($landing_min =="") 
$errorstring = $errorstring. "Landing Minutes<br>";


// does the errorstring = "nothing"?
if ($errorstring !="")
echo "You have not put anything in the following fields: <br><br> $errorstring";
//echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\"";
//die ("Please try again, ensuring that you fill out all the fields!");
elseif(isset($_POST['save_flight']))
{
//echo "Your data has been saved";
//connect to database
mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error());
mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error());

$insert_query = "INSERT INTO pilots_logbook (date, type, reg_01, reg_02, captain, passenger, where_01, where_02, takeoff_hr, takeoff_min, landing_hr, landing_min, ws_captain_hrs, ws_captain_min, ws_student_hrs, ws_student_min, three_captain_hrs, three_captain_min, three_student_hrs, three_student_min, passenger_hrs, passenger_min, remarks) VALUES ('$date', '$type', '$reg_01', '$reg_02', '$captain', '$passenger', '$where_01', '$where_02', '$takeoff_hr', '$takeoff_min', '$landing_hr', '$landing_min', '$ws_captain_hrs', '$ws_captain_min', '$ws_student_hrs', '$ws_student_min', '$three_captain_hrs', '$three_captain_min', '$three_student_hrs', '$three_student_min','$passenger_hrs', '$passenger_min', '$remarks')";
$insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query);

$id = mysql_insert_id();

echo "Thank you, Your logbook entry has been saved.";
}
}

?>
<p>Use this form to add an entry to your logbook.</p>
<form name="form1" method="post" action="index1.php">
<table width="650" border="1" cellspacing="0" cellpadding="5">
<tr>
<td>Required *</td>
<td> </td>
<td>This Format Only</td>
</tr>
<tr>
<td width="180">Date *</td>
<td width="300">
	<input type="text" name="date" id="date" size="40"/ value="<?php echo $today; ?>" /></td>
<td width="170">YYYY-MM-DD</td>
</tr>
<tr>
<td>Aircraft Type *</td>
<td><input type="text" name="type" id="type" size="40" / value="<?php echo $type; ?>" /></td>
<td>E.G. Quantum</td>
</tr>
<tr>
<td>Reg Number *</td>
<td><input type="text" name="reg_01" id="reg_01" size="5" value="<?php echo $reg_01; ?>" /> - <input type="text" name="reg_02" id="reg_02" size="15" value="<?php echo $reg_02; ?>" /></td>
<td>G - ABCD</td>
</tr>
<tr>
<td>Captain *</td>
<td><input type="text" name="captain" id="captain" size="40" value="<?php echo $captain; ?>" /></td>
<td>Name of Captain</td>
</tr>
<tr>
<td>Passenger or Student</td>
<td><input type="text" name="passenger" id="passenger" size="40" value="<?php echo $passenger; ?>" /></td>
<td>Were you? P or S</td>
</tr>
<tr>
<td>Flight From *</td>
<td><input type="text" name="where_01" id="where_01" size="40" value="<?php echo $where_01; ?>" /></td>
<td>Take off Airfield</td>
</tr>
<tr>
<td>Flight To *</td>
<td><input type="text" name="where_02" id="where_02" size="40" value="<?php echo $where_02; ?>" /></td>
<td>Landing Airfield</td>
</tr>
<tr>
<td>Takeoff GMT *</td>
<td>
	<label>
		Hr <input type="text" name="takeoff_hr" id="takeoff_hr" size="10" value="<?php echo $takeoff_hr; ?>" />
		Min <input type="text" name="takeoff_min" id="takeoff_min" size="10" value="<?php echo $takeoff_min; ?>" />
	</label>
</td>
<td>24 Hr Format Only</td>
</tr>
<tr>
<td>Landing GMT *</td>
<td>
	<label>
		Hr <input type="text" name="landing_hr" id="landing_hr" size="10" value="<?php echo $landing_hr; ?>" />
		Min <input type="text" name="landing_min" id="landing_min" size="10" value="<?php echo $landing_min; ?>" />
	</label>
</td>
<td>24 Hr Format Only</td>
</tr>
<tr>
<td>Captain Weighshift</td>
<td>
	<label>Hrs <input type="text" name="ws_captain_hrs" id="ws_captain_hrs" size="10" value="<?php echo $ws_captain_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="ws_captain_min" id="ws_captain_min" size="10" value="<?php echo $ws_captain_min; ?>" />
		<input type="submit" name="autofill_ws_captain" id="autofill_ws_captain" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Student Weightshift</td>
<td>
	<label>Hrs <input type="text" name="ws_student_hrs" id="ws_student_hrs" size="10" value="<?php echo $ws_student_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="ws_student_min" id="ws_student_min" size="10" value="<?php echo $ws_student_min; ?>" />
		<input type="submit" name="autofill_ws_student" id="autofill_ws_student" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Captain 3 Axis</td>
<td>
	<label>Hrs <input type="text" name="three_captain_hrs" id="three_captain_hrs" size="10" value="<?php echo $three_captain_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="three_captain_min" id="three_captain_min" size="10" value="<?php echo $three_captain_min; ?>" />
		<input type="submit" name="autofill_3_captain" id="autofill_3_captain" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Student 3 Axis</td>
<td>
	<label>Hrs <input type="text" name="three_student_hrs" id="three_student_hrs" size="10" value="<?php echo $three_student_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="three_student_min" id="three_student_min" size="10" value="<?php echo $three_student_min; ?>" />
		<input type="submit" name="autofill_3_student" id="autofill_3_student" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Passenger Interest Only</td>
<td>
	Hrs <input type="text" name="passenger_hrs" id="passenger_hrs" size="10" value="<?php echo $passenger_hrs; ?>" />
	Min <input type="text" name="passenger_min" id="passenger_min" size="10" value="<?php echo $passenger_min; ?>" />
	<input type="submit" name="passenger_button" id="passenger_button" value="Auto Insert" />
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Remarks</td>
<td><textarea name="remarks" id="remarks" cols="45" rows="5"><?php echo $remarks; ?></textarea></td>
<td>Went to get microlight forum cup from XYZ airfield. Maximum 500 characters</td>
</tr>
<tr>
<td><input type="submit" name="save_flight" id="save_flight" value="Save Flight" /></td>
<td><input type="submit" name="reset" id="reset" value="Reset Form" /></td>
<td> </td>
</tr>
</table>
<p> </p>
<p> </p>
</body>
</html>

 

Link to comment
Share on other sites

Wait a minute. I take back the part about it being the only parse error. The error marker was hidden at the bottom of my editor . . . You're short one closing } curly brace in the code as well. You should have error_reporting = -1 and display_errors = On while developing. These errors would be reported and you probably could have had them sorted in less time than it took to post here.

Link to comment
Share on other sites

Hi Zer0Day, thanks for that.

 

Essentially the different buttons do the same thing.  When you go flying you can be one of either but not two of. 

 

In other words the button should do the same for each discipline.  It just takes the time that the pilot / student has done and puts it into the correct box.

 

So, just like you have done for "captain Weightshift"

 

The pilot / student goes for a flight.  The flight time is from take off to landing.  They put this time in the boxes Take Off Hrs and Take off Mins, then Landing Hrs and Landing Mins.

 

The time of the flight should then be inserted in any of the 5 boxes dependent upon whether the Pilot is a

"captain of a weightshift aircraft"

"Student in a weightshift aircraft"

Captain in a 3 axis aircraft

Student in a 3 axis aircraft

Or is a passenger and the flight is for interest only.

 

 

Link to comment
Share on other sites

This should get them all working:

 

<?php
if(isset($_POST['reset'])) {
header('Location: index2.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

$host = 'localhost';
$usr = "vinny";
$password = 'thepassword';
$db_name = 'logbook';

$date = $_POST['date'];
$type = $_POST['type'];
$reg_01 = $_POST['reg_01'];
$reg_02 = $_POST['reg_02'];
$captain = $_POST['captain'];
$passenger = $_POST['passenger'];
$where_01 = $_POST['where_01'];
$where_02 = $_POST['where_02'];
$takeoff_hr = $_POST['takeoff_hr'];
$takeoff_min = $_POST['takeoff_min'];
$landing_hr = $_POST['landing_hr'];
$landing_min = $_POST['landing_min'];
$ws_captain_hrs = $_POST['ws_captain_hrs'];
$ws_captain_min = $_POST['ws_captain_min'];
$ws_student_hrs = $_POST['ws_student_hrs'];
$ws_student_min = $_POST['ws_student_min'];
$three_captain_hrs = $_POST['three_captain_hrs']; 
$three_captain_min = $_POST['three_captain_min'];
$three_student_hrs = $_POST['three_student_hrs'];
$three_student_min = $_POST['three_student_min'];
$passenger_hrs = $_POST['passenger_hrs'];
$passenger_min = $_POST['passenger_min'];
$remarks = $_POST['remarks'];

if(isset($_POST['takeoff_hr']) && isset($_POST['takeoff_min']) && isset($_POST['landing_hr']) && isset($_POST['landing_min'])) {
if(isset($_POST['autofill_ws_captain']))
	$formId = "ws_captain";
if(isset($_POST['autofill_ws_student']))
	$formId = "ws_student";
if(isset($_POST['autofill_3_captain']))
	$formId = "three_captain";
if(isset($_POST['autofill_3_student']))
	$formId = "three_student";
if(isset($_POST['passenger_button']))
	$formId = "passenger";

if(strlen($formId) > 1) {
	$hrs = $formId."_hrs";
	$min = $formId."_min";
	$$hrs = $takeoff_hr - $landing_hr;
	$$hrs = str_replace("-", "", $$hrs);
	if(strlen($$hrs) == "1") {
		$$hrs = "0".$$hrs;
	}
	$$min = $takeoff_min - $landing_min;
	$$min = str_replace("-", "", $$min);
	if(strlen($$min) == "1") {
		$$min = "0".$$min;
	}
}
}

if(isset($_POST['today'])) {
$date = date("Y-m-d");
}

$errorstring = ""; // default value of errorstring

if(isset($_POST['save_flight'])) {
// Validate all the code inputs that are required fields
if ($date =="")
$errorstring = $errorstring. "Date<br>";
if ($type =="")
$errorstring = $errorstring. "Aircraft Type<br>";
if ($reg_01 =="")
$errorstring = $errorstring. "Reg Prefix<br>"; 
if ($reg_02 =="")
$errorstring = $errorstring. "Registration Mark<br>";
if ($captain =="")
$errorstring = $errorstring. "Captain<br>";
if ($where_01 =="")
$errorstring = $errorstring. "Flight From<br>";
if ($where_02 =="")
$errorstring = $errorstring. "Flight To<br>";
if ($takeoff_hr =="")
$errorstring = $errorstring. "Takeoff Hours<br>";
if ($takeoff_min =="") 
$errorstring = $errorstring. "Takeoff Minutes<br>";
if ($landing_hr =="")
$errorstring = $errorstring. "Landing Hours<br>";
if ($landing_min =="") 
$errorstring = $errorstring. "Landing Minutes<br>";


// does the errorstring = "nothing"?
if ($errorstring !="")
echo "You have not put anything in the following fields: <br><br> $errorstring";
//echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\"";
//die ("Please try again, ensuring that you fill out all the fields!");
elseif(isset($_POST['save_flight']))
{
//echo "Your data has been saved";
//connect to database
mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error());
mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error());

$insert_query = "INSERT INTO pilots_logbook (date, type, reg_01, reg_02, captain, passenger, where_01, where_02, takeoff_hr, takeoff_min, landing_hr, landing_min, ws_captain_hrs, ws_captain_min, ws_student_hrs, ws_student_min, three_captain_hrs, three_captain_min, three_student_hrs, three_student_min, passenger_hrs, passenger_min, remarks) VALUES ('$date', '$type', '$reg_01', '$reg_02', '$captain', '$passenger', '$where_01', '$where_02', '$takeoff_hr', '$takeoff_min', '$landing_hr', '$landing_min', '$ws_captain_hrs', '$ws_captain_min', '$ws_student_hrs', '$ws_student_min', '$three_captain_hrs', '$three_captain_min', '$three_student_hrs', '$three_student_min','$passenger_hrs', '$passenger_min', '$remarks')";
$insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query);

$id = mysql_insert_id();

echo "Thank you, Your logbook entry has been saved.";
}
}

?>
<p>Use this form to add an entry to your logbook.</p>
<form name="form1" method="post" action="index2.php">
<table width="650" border="1" cellspacing="0" cellpadding="5">
<tr>
<td>Required *</td>
<td> </td>
<td>This Format Only</td>
</tr>
<tr>
<td width="180">Date *</td>
<td width="300">
	<input type="text" name="date" id="date" size="25"/ value="<?php echo $date; ?>" />
	<input type="submit" name="today" id="today" value="Add Today" />
</td>
<td width="170">YYYY-MM-DD</td>
</tr>
<tr>
<td>Aircraft Type *</td>
<td><input type="text" name="type" id="type" size="40" / value="<?php echo $type; ?>" /></td>
<td>E.G. Quantum</td>
</tr>
<tr>
<td>Reg Number *</td>
<td><input type="text" name="reg_01" id="reg_01" size="5" value="<?php echo $reg_01; ?>" /> - <input type="text" name="reg_02" id="reg_02" size="15" value="<?php echo $reg_02; ?>" /></td>
<td>G - ABCD</td>
</tr>
<tr>
<td>Captain *</td>
<td><input type="text" name="captain" id="captain" size="40" value="<?php echo $captain; ?>" /></td>
<td>Name of Captain</td>
</tr>
<tr>
<td>Passenger or Student</td>
<td><input type="text" name="passenger" id="passenger" size="40" value="<?php echo $passenger; ?>" /></td>
<td>Were you? P or S</td>
</tr>
<tr>
<td>Flight From *</td>
<td><input type="text" name="where_01" id="where_01" size="40" value="<?php echo $where_01; ?>" /></td>
<td>Take off Airfield</td>
</tr>
<tr>
<td>Flight To *</td>
<td><input type="text" name="where_02" id="where_02" size="40" value="<?php echo $where_02; ?>" /></td>
<td>Landing Airfield</td>
</tr>
<tr>
<td>Takeoff GMT *</td>
<td>
	<label>
		Hr <input type="text" name="takeoff_hr" id="takeoff_hr" size="10" value="<?php echo $takeoff_hr; ?>" />
		Min <input type="text" name="takeoff_min" id="takeoff_min" size="10" value="<?php echo $takeoff_min; ?>" />
	</label>
</td>
<td>24 Hr Format Only</td>
</tr>
<tr>
<td>Landing GMT *</td>
<td>
	<label>
		Hr <input type="text" name="landing_hr" id="landing_hr" size="10" value="<?php echo $landing_hr; ?>" />
		Min <input type="text" name="landing_min" id="landing_min" size="10" value="<?php echo $landing_min; ?>" />
	</label>
</td>
<td>24 Hr Format Only</td>
</tr>
<tr>
<td>Captain Weighshift</td>
<td>
	<label>Hrs <input type="text" name="ws_captain_hrs" id="ws_captain_hrs" size="10" value="<?php echo $ws_captain_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="ws_captain_min" id="ws_captain_min" size="10" value="<?php echo $ws_captain_min; ?>" />
		<input type="submit" name="autofill_ws_captain" id="autofill_ws_captain" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Student Weightshift</td>
<td>
	<label>Hrs <input type="text" name="ws_student_hrs" id="ws_student_hrs" size="10" value="<?php echo $ws_student_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="ws_student_min" id="ws_student_min" size="10" value="<?php echo $ws_student_min; ?>" />
		<input type="submit" name="autofill_ws_student" id="autofill_ws_student" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Captain 3 Axis</td>
<td>
	<label>Hrs <input type="text" name="three_captain_hrs" id="three_captain_hrs" size="10" value="<?php echo $three_captain_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="three_captain_min" id="three_captain_min" size="10" value="<?php echo $three_captain_min; ?>" />
		<input type="submit" name="autofill_3_captain" id="autofill_3_captain" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Student 3 Axis</td>
<td>
	<label>Hrs <input type="text" name="three_student_hrs" id="three_student_hrs" size="10" value="<?php echo $three_student_hrs; ?>" /></label>
	<label>
		Min <input type="text" name="three_student_min" id="three_student_min" size="10" value="<?php echo $three_student_min; ?>" />
		<input type="submit" name="autofill_3_student" id="autofill_3_student" value="Auto Insert" />
	</label>
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Passenger Interest Only</td>
<td>
	Hrs <input type="text" name="passenger_hrs" id="passenger_hrs" size="10" value="<?php echo $passenger_hrs; ?>" />
	Min <input type="text" name="passenger_min" id="passenger_min" size="10" value="<?php echo $passenger_min; ?>" />
	<input type="submit" name="passenger_button" id="passenger_button" value="Auto Insert" />
</td>
<td>Button works it out and inserts it here</td>
</tr>
<tr>
<td>Remarks</td>
<td><textarea name="remarks" id="remarks" cols="45" rows="5"><?php echo $remarks; ?></textarea></td>
<td>Went to get microlight forum cup from XYZ airfield. Maximum 500 characters</td>
</tr>
<tr>
<td><input type="submit" name="save_flight" id="save_flight" value="Save Flight" /></td>
<td><input type="submit" name="reset" id="reset" value="Reset Form" /></td>
<td> </td>
</tr>
</table>
<p> </p>
<p> </p>
</body>
</html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.