Jump to content
Larry Ullman's Book Forums

microlight

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by microlight

  1. All I am getting is the error message "learn to input data correctly, bozo!" on a separate page logbook_add.php
  2. Brilliant HartleySan. Thank you for all that work, that's amazing. I really appreciate it. I have put everything into the files as indicated, but I must be stupid because I can't get it to work. All I get is the error message. Here are my two files as I have put them together. <!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> <form action="logbook_add.php" method="post"> <table width="527" border="0" cellspacing="5" cellpadding="5" bgcolor="#c0c5c9"> <tr> <td width="146">Entry 01</td> <td width="346"><input type="int" name="hour01" size="10" maxlength="10" /> Hrs <input type="int" name="min01" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 02</td> <td><input type="int" name="hour02" size="10" maxlength="10" /> Hrs <input type="int" name="min02" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 03</td> <td><input type="int" name="hour03" size="10" maxlength="10" /> Hrs <input type="int" name="min03" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 04</td> <td><input type="int" name="hour04" size="10" maxlength="10" /> Hrs <input type="int" name="min04" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 05</td> <td><input type="int" name="hour05" size="10" maxlength="10" /> Hrs <input type="int" name="min05" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 06</td> <td><input type="int" name="hour06" size="10" maxlength="10" /> Hrs <input type="int" name="min06" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 07</td> <td><input type="int" name="hour07" size="10" maxlength="10" /> Hrs <input type="int" name="min07" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 08</td> <td><input type="int" name="hour08" size="10" maxlength="10" /> Hrs <input type="int" name="min08" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 09</td> <td><input type="int" name="hour09" size="10" maxlength="10" /> Hrs <input type="int" name="min09" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 10</td> <td><input type="int" name="hour10" size="10" maxlength="10" /> Hrs <input type="int" name="min10" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 11</td> <td><input type="int" name="hour11" size="10" maxlength="10" /> Hrs <input type="int" name="min11" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 12</td> <td><input type="int" name="hour12" size="10" maxlength="10" /> Hrs <input type="int" name="min12" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td><input type="submit" name="submit" value="Add Your Logbook Times" /></td> <td>Answer <input type="int" size ="10" value="<?php if (!empty($iTotalHours)) echo $iTotalHours; ?>" /> <input type="int" size="10" value="<?php if (!empty($iTotalMin)) echo $iTotalMin; ?>"/> </td> </tr> </table> <div align="center"></div></form> </body> </html> Then logbook_add.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 $iTotalHours = 0; $iTotalMin = 0; $bIsHourValue = true; // Used to alternate between hour and minute values in the POST array. $bNoErrors = true; // Flag used to indicate that there is some invalid input. foreach ($_POST as $key => $value) { // $key represents the names of the various submitted data items (e.g., hour01, min01, hour02, etc.). if ($bIsHourValue) { // Is an hour value. if (is_int($value)) { // PHP function testing for an integer $iTotalHours .= $value; } else if (!empty($value)) { // If we get here, we know that we don't have an integer, so if there is any value at all, then it must be invalid. // If it's empty, we don't need to do anything. $bNoErrors = false; break; // No need to continue the loop if we've already found an error. Note that this is fairly rudimentary error handling. } $bIsHourValue = false; // Alternate the isHour flag. } else { // Is a minute value. if (is_int($value)) { $iTotalMin .= $value; } else if (!empty($value)) { $bNoErrors = false; break; } $bIsHourValue = true; } } if ($bNoErrors) { // If there was no invalid input, do the calculations. $iTotalMin .= 60 * $iTotalHours; // Total time in minutes $iTotalHours = floor($iTotalMin / 60); // Divide the total time by 60, and round the result down to the nearest integer for the total hours. $iTotalMin %= 60; // Kind of a funky notation, but takes the total minutes and sets it equal to the reminder of itself divided by 60. // For example 280 % 60 = 40 (minutes). } else { // Output a basic message indicating that there was some invalid input. echo 'Learn to input data correctly, bozo!'; } ?> </body> </html> Please can you tell me what I've done wrong?
  3. Brilliant, thank you HartleySan. By the way, I work for Toyota here in the UK, just noticed you were in Japan.
  4. Hi HartleySan and Jonothan, thank you for your replies. The log book entries are 12 per page. Simply adding them up in the hour and minute format is what I want to achieve. I don't mind the values being deleted when I close the browser window. Here is a screen shot of the code for add_logbook.php in the browser window. I would also like it to work (adding '0') if the user puts nothing in the box and also give them an error if they put letters instead of numbers (capture none integers)
  5. Hi People. I fly a flexwing microlight aircraft and I am trying to write a calculator that adds up time for my website and my logbook. You see as a pilot we have to keep a valid logbook and the pages are set out in 12s we then need to add up the times. My idea is that I have a list of boxes to put in your hours and minutes. Then click the calculate button and it adds up your time and displays it in the box at the bottom. My code needs to do this...... add up all 12 minute boxes, add up all the hours boxes and multiply it by 60, add both results to get the total minutes, then run through a loop to do the following. check to see if variable "total minutes" >60 and if so add 1 to the hour variable, continue through the loop until the condition >60 in the minutes is not met. Then put the resulting hours and minutes into the result box. Here is the code so far, any help would really be appreciated. <!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> <form action="logbook_add.php" method="post"> <table width="527" border="0" cellspacing="5" cellpadding="5" bgcolor="#c0c5c9"> <tr> <td width="146">Entry 01</td> <td width="346"><input type="int" name="hour01" size="10" maxlength="10" /> Hrs <input type="int" name="min01" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 02</td> <td><input type="int" name="hour02" size="10" maxlength="10" /> Hrs <input type="int" name="min02" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 03</td> <td><input type="int" name="hour03" size="10" maxlength="10" /> Hrs <input type="int" name="min03" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 04</td> <td><input type="int" name="hour04" size="10" maxlength="10" /> Hrs <input type="int" name="min04" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 05</td> <td><input type="int" name="hour05" size="10" maxlength="10" /> Hrs <input type="int" name="min05" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 06</td> <td><input type="int" name="hour06" size="10" maxlength="10" /> Hrs <input type="int" name="min06" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 07</td> <td><input type="int" name="hour07" size="10" maxlength="10" /> Hrs <input type="int" name="min07" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 08</td> <td><input type="int" name="hour08" size="10" maxlength="10" /> Hrs <input type="int" name="min08" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 09</td> <td><input type="int" name="hour09" size="10" maxlength="10" /> Hrs <input type="int" name="min09" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 10</td> <td><input type="int" name="hour10" size="10" maxlength="10" /> Hrs <input type="int" name="min10" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 11</td> <td><input type="int" name="hour11" size="10" maxlength="10" /> Hrs <input type="int" name="min11" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td>Entry 12</td> <td><input type="int" name="hour12" size="10" maxlength="10" /> Hrs <input type="int" name="min12" size="10" maxlength="10" /> whole mins</td> </tr> <tr> <td><input type="submit" name="submit" value="Add Your Logbook Times" /></td> <td>Answer <input type="int" name="hour_answer" size="10" maxlength="10" /> <!--<input type="hidden" name="submitted" value ="1" /> --> Hrs <input type="int" name="min_answer" size="10" maxlength="10" /> mins</td> </tr> </table> <div align="center"></div></form> </body> </html> Here is the php I have so far. <!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 /* $hour01 $hour02 $hour03 $hour04 $hour05 $hour06 $hour07 $hour08 $hour09 $hour10 $hour11 $hour12 $min01 $min02 $min03 $min04 $min05 $min06 $min07 $min08 $min09 $min10 $min11 $min12 */ $total_mins //$total_hours //$total_time_in_mins //$min_answer //$hour_answer //if (isset($_POST['submitted'])) $total_mins = ([$_POST['min01'] + [$_POST['min02'] + [$_POST['min03'] + [$_POST['min04']+[$_POST['min05']+[$_POST['min06']+[$_POST['min07']+[$_POST['min08']+[$_POST['min09']+[$_POST['min10']+[$_POST['min11']+[$_POST['min12']); 'min_answer' = $total_mins; //$total_mins = $total_hours * 60; //$total_mins = ?> </body> </html>
  6. Brilliant, thanks, it now works, For the benefit of others following in our footsteps, please could you highlight where the errors were? I would like to see why I am the dickbrain! Regards Microlight.
  7. Hi People. Here is my code from chapter 2 and I get an error I cannot understand, and don't know where I've gone wrong. Please can someone help. Here is the error I get.... Parse error: syntax error, unexpected $end in /Users/dog_snob/Sites/phpmyql3_scripts/ch01/handle_form.php on line 93 From what I understand from the error it is stating that it's reached the end of the file unexpectedly. I've checked each line of code 3 times and can't see the wood for the trees. It is as per the book as far as I can see. <!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>Handle the Form</title> <style type="text/css" title="text/css" media="all"> .error {font-weight: bold; color; #c00 } </style> </head> <body> <?php # ### script 2.4 handle form handle_form.php // Validate the name: if (!empty($_REQUEST['name'])) { $name =$_REQUEST['name']; } else { $name=NULL; echo '<p class="error"> You forgot to enter your name!</p>'; } // validate email if (!empty($_REQUEST['email'])) { $email=$_REQUEST['email']; } else { $email=NULL; echo '<p class="error"> You forgot to enter your email address!</p>'; } // validate comments if (!empty($_REQUEST['comments'])) { $comments=$_REQUEST['comments']; } else { $comments=NULL; echo '<p class="error"> You forgot to enter any comments!</p>'; } // validate gender if (isset($_REQUEST['gender'])); { $gender=$_REQUEST['gender']; if($gender == 'M'){ echo '<p><b>Good Day, Sir!</b></p>'; } elseif ($gender == 'F'){ echo '<p><b>Good Day, Madam!</b></p>'; } else { //$_REQUEST['gender'] is not set $gender = NULL; echo '<p class="error"> You forgot to select your gender!</p>'; } // if everything else is OK then print this message. if ($name && $email && $gender && $comments) { echo "<p> Thank you, <b>$name</b>, for the following comments:</br> <tt>$comments</tt></p> <p>We will reply to you at <i>$email</i>.</p>\n"; } else { // missing form value. echo '<p class="error">Please go back and fill out the form correctly you dickbrain.</p>'; } ?> </body> </html>
×
×
  • Create New...