i keep getting an undefined index: comments error and an undefined index: comments error
could you please look at my code to tell me where im going wrong
$comments = $_POST["comments"];
//check comment has been entered
if (strlen($comments) > 0) {
$comments = stripslashes($comments);
} else { // if there are no comments..
$comments = NULL;
echo '<p><font color="red" size"+1">You forgot to enter your comments!</b</p>';
}
//if everything was filled out ok
if ($username && $email && $comments) { // if everything's ok
//Add comments
$query = "INSERT INTO guestbook (username, email, comments) VALUES ('$username','$email','$comments')";
$result = @mysql_query ($query); // run the query.
if ($result) { // If it ran ok.
echo '<h3>Thank you for leaving a comments!</h3>';
include ('includes/footer.html'); // include the HTML footer.
exit();
} else { // If it did not run ok.
echo '<p><font color="red" size="+1">You could not leave a comment due to a system error. We apologise for any inconvenience.</font></p>';
}
mysql_close(); // Close the database connection.
}
}
?>
<h1>Guestbook</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<p><b>User Name:</b> <input type="text" name="username" size"10" maxlength="20"
value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
<p><b>Email Address:</b> <input type="text" name="email" size"40" maxlength="40"
value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p><b>Comments:<b> <textarea name="comments" rows="5" cols="30"></textarea
"<?php if (isset($_POST['comments'])) echo $_POST['comments']; ?>" > </p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
</form><!-- End of form -->
<?php // inlcude the HTML footer.
include ('includes/footer.html');
?>