Hi
My form validation array is not looping enough. It just displays one of the errors even if there are two.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
</head>
<body>
<div id="container">
<?php
if (isset($_POST['submit']))
{
$error = '';
$title = stripslashes(trim($_POST['title']));
$content = stripslashes(trim($_POST['content']));
if(!$title)
{
$error[] = "Title";
}
if(!$content)
{
$error[] = "Content";
}
if($error)
{
foreach ($error as $value)
{
$errors = "<li>" . $value . "</li>";
}
$message = '<p class="error">Please check your</p><ul>' . $errors . '</ul>';
}
else
{
require("databaseconnect.php");
$date = date('l dS \of F Y');
$query = "INSERT INTO blog (title, body, date) VALUES ('$title', '$body', '$date')";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
mysql_close($connection);
$message = '<p class="confirm">You have just posted on your blog</p>';
}
}
?>
<?php echo $message ?>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<label for="title">Title:</label><input type="text" name="title" /><br />
<label for="body">Body:</label><textarea name="content" /></textarea><br />
<input type="submit" name="submit">
</form>
</div>
</body>
</html>
Any ideas?