This is a comment system that I wrote, is it secure?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<?PHP
//Turn off error reporting (Not Necessary)
error_reporting(E_ALL ^ E_NOTICE);
//Connect to the database
if (!@mysql_connect('localhost', 'user', '') or !@mysql_select_db('comments')) {
die('Could not connect, please check back later.');
}
//Variables
$guest_name = htmlentities(str_replace(' ', '',$_POST['guest_name']));
$comment = htmlentities($_POST['comment']);
$time = date('g:i A', time());
$date = date('n/j/Y');
$query = "INSERT INTO `user_comments` VALUES(
'".mysql_real_escape_string('')."',
'".mysql_real_escape_string($guest_name)."',
'".mysql_real_escape_string($comment)."',
'".mysql_real_escape_string($date)."',
'".mysql_real_escape_string($time)."'
)";
$array_query = mysql_query("SELECT * FROM `comments` ORDER BY `ID` DESC");
//Insert comment into the database
if (isset($_POST['submit_comment']) && !empty($comment) && !empty($guest_name)) {
if(mysql_query($query)) {
header('Location: index.php');
}
}
//Check if user has filled in all fields
if (isset($_POST['submit_comment']) && empty($guest_name)) {
echo '<span style="color:red">*Please enter a Guest Name*</span><br>';
}
if (isset($_POST['submit_comment']) && empty($comment)) {
echo '<span style="color:red">*Please enter a Comment*</span>';
}
//List comments
function list_comments () {
$query = "SELECT * FROM `user_comments` ORDER BY `ID` DESC";
$query_run = mysql_query($query);
while ($result = mysql_fetch_array($query_run)) {
echo '<div id="comment_border">' . $result['Guest Name'] . ' - ' . $result['Date'] . ' - ' . $result['Time'] . '<br>' . $result['Comment'] . '<br></div><br>';
}
};
?>
<title>Main_Page</title>
</head>
<body>
<!-- \/ COMMENT FORM \/ -->
<form method="post" action="index.php">
<input type="text" name="guest_name" maxlength="15" placeholder="Guest Name"><br>
<textarea cols="70" rows="5" name="comment" maxlength="512" placeholder="Comment"></textarea>
<input type="submit" name="submit_comment">
</form>
<!-- /\ COMMENT FORM /\ -->
<hr><h1>Comments</h1><br>
<!-- Comments will list below here -->
<?PHP
list_comments();
?>
</body>
</html>