Lab Work 2
Lab Work 2
Lab Work 2
</fieldset>
</form>
</body>
</html>
2. Managing HTML Form with PHP (handle_registration.php)
<html>
<head>
<title>Form Feedback</title>
</head>
<body>
<?php
?>
</body>
</html>
1
PHP and MySQL for Dynamic Websites
</form>
</body>
</html>
Data Validation (handle_register.php)
<html>
<head>
<title>Form Feedback</title>
</head>
<body>
<?php
// Validate name
if (!empty($_POST['name'])) {
$name = $_POST['name'];
} else {
$name = NULL;
echo '<p><b>You forgot to enter your name!</b></p>';
}
} else {// One form element was not filled out properly.
echo '<p><font color="red">Please go back and fill out the form again.</font></p>';
}
?>
2
PHP and MySQL for Dynamic Websites
</body>
</html>
Try this! – add email and validate the email (print screen the output)
<fieldset><legend>Calculate tax:</legend>
<p><b>Quantity:</b> <input type="text" name="quantity" size="20" maxlength="40" /></p>
<p><b>Price(RM):</b> <input type="text" name="price" size="20" maxlength="40" /></p>
<p><b>Tax rate(%):</b> <input type="text" name="tax" size="20" maxlength="40" /></p>
</fieldset>
</form>
</body>
</html>
// Validate quantity
if (!empty($_POST['quantity'])) {
$quantity = $_POST['quantity'];
} else {
$quantity = NULL;
echo '<p><b>You forgot to enter your quantity!</b></p>';
}
// Validate price
if (!empty($_POST['price'])) {
$price = $_POST['price'];
} else {
$price = NULL;
echo '<p><b>You forgot to enter your price!</b></p>';
}
// Validate tax
if (!empty($_POST['tax'])) {
$tax = $_POST['tax'];
} else {
$tax = NULL;
echo '<p><b>You forgot to enter your tax!</b></p>';
}
3
PHP and MySQL for Dynamic Websites
</body>
</html>
4
PHP and MySQL for Dynamic Websites