I've been following the video's to the letter, literally , but still don't get the error message when not all fields in the form are filled in.
Here is my code (but, if it's easier for you, send me yours and I'll be able to figure it out by myself).
Thanks,
judith
records.php
<?php
function renderForm($first = '', $last = '' , $error = '', $id = '')
{ ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
<?php
if ($id !='')
{
echo "Edit Record";
}
else
{
echo "New Record";
}
?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>
<?php
if ($id !='')
{
echo "Edit Record";
}
else
{
echo "New Record";
}
?>
</h1>
<?php
if ($error !='')
{
echo "<div style='padding:4px; border:1px solid red; color:red" . $error . "</div>";
}
?>
<form action="" method="post">
<div>
<?php
if ($id != ''){ ?>
<input type="hidden" name="id" value="<?php echo $id;?>" />
<p>ID: <?php echo $id; ?></p>
<?php }
?>
<strong> First name: *</strong> <input type="text" name="firstname"
value="<?php echo $first; ?>" /> <br />
<strong> Last name: *</strong> <input type="text" name="lastname"
value="<?php echo $last; ?>" />
<p>* required </p>
<input type="submit" name="submit" value="submit" />
</div>
</form>
</body>
</html>
<?php }
if (isset($_GET['id']))
{
//echo "id is set"; //TEST
//editing existing record
renderForm(NULL, NULL, NULL, $_GET['id']);
}
else
{
//echo "id is not set"; //TEST
//creating new record
if (isset($_POST['submit']))
{
$firstname = htmlentities($_POST['firstname'], ENT_QUOTES);
$lastname = htmlentities($_POST['lastname'], ENT_QUOTES);
if ($firstname == '' || $lastname == '')
{
$error = 'ERROR: please fill in all required fields';
renderForm($firstname, $lastname, $error); //if the user entered one of the fields, he doesn't lose that
}
}
else
{
renderForm();
}
}
?>