Let's Get Started with a PHP/MySQL Form Page!

  1. Open Notepad++
  2. Choose: File -> New
  3. Copy the PHP Form Template (PHP) code (below)
  4. Paste that code into your new file
  5. Change the put-title-of-this-page-here
  6. Click: File -> Save As
  7. Name your file: \www\form.php
  8. Change the Save as type: to: PHP Hypertext Preprocessor (*.php)
  9. Click: Save
  10. Start your local web server if it is not already running
  11. Visit your page (http://localhost/form.php) in your favorite web browser
  12. Make any changes
  13. Save your changes
  14. Fill in the form fields
  15. Submit your form
  16. View your form.php page to see if the temperatur conversion worked
  17. Change: $debug = 0;
    to: $debug = 1;
  18. Add another record to see the debug messages

PHP Form Template (PHP)

<?php 
$debug = 0;
if (isset($_POST['submit'])) {
  if ($debug) {
    foreach ($_POST as $postElement => $postValue) {
      echo("\$_POST[$postElement] = $postValue<br/>\n");
    }
  }
  $firstName = $_POST['firstName'];
  $lastName  = $_POST['lastName'];
  $far = $_POST['far'];
  echo("Hello $firstName $lastName<br/>");
  include("inc_temp.php");
  convertTemp($far);
}
?>
<!doctype html>
<html>
  <head>
    <title>put-title-of-this-page-here</title>
  </head>
  <body>
  <h1>My Form Page</h1>
    <form id="tempForm" method="POST" action="form.php">
      <fieldset> 
      <legend>Temperature Information<legend> 
      <label for="firstName">First Name:</label> 
      <input id="firstName" name="firstName" type="text"/><br style="clear: both;"> 
      <label for="lastName">Last Name:</label> 
      <input id="lastName" name="lastName" type="text"/><br style="clear: both;">
      <label for="far">Farenheight:</label> 
      <input id="far" name="far" type="text"/><br style="clear: both;">
      </fieldset> 
      <label for="submit"></label>
      <button id="submit" name="submit" type="submit" 
      value="Do it!"/>Do it!</button><br style="clear: both;">
    </form>  
  </body>
</html>

Output