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)

$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/>");
<!doctype html>
  <h1>My Form Page</h1>
    <form id="tempForm" method="POST" action="form.php">
      <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;">
      <label for="submit"></label>
      <button id="submit" name="submit" type="submit" 
      value="Do it!"/>Do it!</button><br style="clear: both;">