Let's Get Started with a PHP/MySQL Form Page!
- Open Notepad++
- Choose:
File -> New
- Copy the PHP Form Template (PHP) code (below)
- Paste that code into your new file
- Change the put-title-of-this-page-here
- Click: File -> Save As
- Name your file: \www\form.php
- Change the
Save as type:
to: PHP Hypertext Preprocessor (*.php)
- Click: Save
- Visit your page (http://buffalo.edu/form.php) in your favorite web browser
- Make any changes
- Save your changes
- Fill in the form fields
- Submit your form
- View your
form.php
page to see if the temperatur conversion worked
- Change:
$debug = 0;
to: $debug = 1;
- 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