You can modify the code and add some judgment:
elseif(empty($_POST['comment'])){
echo "Hey, please say a few more words~";
}
else{
$sql = "INSERT INTO myblog_comments(blog_id, dateposted, name, comment) VALUES(" . $validentry . ", NOW(), '" . $_POST['name'] . "', '" . $_POST['comment'] . " ');";
mysql_query($sql);
header("Location: http://". $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']."?id=" . $validentry);
}
PHP null value judgment
Although empty and isset are both variable processing functions, they are both used to determine whether the variable has been configured, but they have certain differences: empty will also detect whether the variable is empty or zero. When a variable value is 0, empty considers the variable to be equivalent to being empty, which is equivalent to not being set.
To summarize, "NULL" and "empty" are two concepts in PHP.
isset is mainly used to determine whether a variable has been initialized.
empty can judge variables with values of "false", "empty", "0", "NULL" and "uninitialized" as TRUE
is_null Only variables with a value of "NULL" are judged as TRUE
var == null Judge variables with a value of "false", "empty", "0", and "NULL" as TRUE
var === null Only variables with a value of "NULL" are judged as TRUE
So when we judge whether a variable is really "NULL", we mostly use is_null to avoid "false", "0" and other values. interference.