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. Visit your page (http://buffalo.edu/form.php) in your favorite web browser
  11. Make any changes
  12. Save your changes
  13. Fill in the form fields
  14. Submit your form
  15. View your form.php page to see if the temperatur conversion worked
  16. Change: $debug = 0;
    to: $debug = 1;
  17. 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