Изменить
<?php
echo"<form method='POST' action='".setComments($conn)."'>
<input type='hidden' name='uid' value='Anonymous'>
<input type='hidden' name='date' value='".date('D-m-y H:i:s')."'>
<textarea name='message'></textarea> <br>
<button type='submit' name='commentSubmit'>Comment</button>
</form>";
?>
На:
<?php
// action empty send the post data to the this fila again
// setComments function have a condition to work only when POST data is present
setComments($conn);
echo"<form method='POST' action=''>
<input type='hidden' name='uid' value='Anonymous'>
<input type='hidden' name='date' value='".date('D-m-y H:i:s')."'>
<textarea name='message'></textarea> <br>
<button type='submit' name='commentSubmit'>Comment</button>
</form>";
?>
И
Это:
$sql = "INSTERT INTO comments (uid, date, message) VALUES ('$uid', '$date', '$message')";
$result = mysql_query(- $sql);
}
К:
// INSERT is the correct sintaxis
$sql = "INSERT INTO comments (uid, date, message) VALUES ('$uid', '$date', '$message')";
$result = mysql_query($sql);
}
Наконец
$conn = mysqli_connect('localhost', 'root', '', 'commentsection');
Кому:
// mysqli_connect have diferent parameters
$conn = mysql_connect('localhost', 'root', '', 'commentsection');
Проверено и работает