[SOLVED]comment form inserting record when null
Posted: Tue Mar 22, 2005 2:52 am
i have this comment form
when the textarea is blank, then i click the submit button, it still records the blank data in the database....pls help
tnx....
Code: Select all
<!--comment form-->
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<?
if (isset($_POST['submit']))
{
$message = NULL;
if (empty($_POST['comment']))
{
$c = FALSE;
$message .= 'Please enter your comment!<br>';
}
else
{
$c = addslashes($_POST['comment']);
}
$updatequery = "UPDATE posts SET postupdate=NOW() WHERE postID='$id'";
$updateresult = @mysql_query($updatequery);
$query = "INSERT INTO comments(comment, postID, username, commentdate)
VALUES('$c','$_GET[pid]','$fn', NOW())";
$result = @mysql_query($query);
if ($updatequery && $result)
{
echo '<b/>Your comment has been posted!';
echo '<meta http-equiv="refresh" content="3;url=http://localhost/mysample/report.php">';
exit();
//}
}
else
{
echo 'Your comment cannot be posted due to system error!'.mysql_error();
}
//mysql_close();
}
if (isset($message))
{
echo '<font color="red">', $message, '</font>';
}
?>
<tr valign="top">
<td width="20%" align="right"><b>COMMENT</b></td>
<td width="1%"><b>:</b></td>
<td width="79%"><textarea name="comment" style="width:350px"cols="40" rows="6"></textarea></td>
</tr>
<tr valign="top">
<td width="20%"></td>
<td width="1%"></td>
<td width="79%"><input type="submit" name="submit" value="submit" class="buttonformat"></td>
</tr>
</table>
</form>tnx....