PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
if(isset($_POST['comments']{
$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>';
//are you sure you want the footer here??
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.
}
}
}
?>
cause $_POST['comments'] is empty! oh, and you have quotes around that php block which are unecesary because in text area tage you can just have plain text not like in attributes where you need to quote it!
if(isset($_POST['comments']{
$comments = $_POST["comments"];
these two?
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>';
}
the I'd say use both - the isset will ensure that you dont get an array index error and you can use strlen and add on to that if statement to ensure that the information is valid and not a script kiddie trying to get control of your code!
if(isset($_POST['comments']{
$comments = $_POST["comments"]; - this line
//check comment has been entered
if (strlen($comments) > 0) {
$comments = stripslashes($comments);
i take it key1 is your primary key and you have it defaulting to "0" so it won't submit because you can't have duplicates on a key so you need to change it to AUTO_INCREMENT or some random thing!