I am trying to filter the user's input from malicious code to prevent XSS attack. When the user submits the input, the input goes trough the following checks... The input is contained in the $post variable.
$post = htmlspecialchars($post);
$id = $_SESSION['loggedIn'];
$sql = "UPDATE playerstats SET message='$post' WHERE id = $id";
$db->query($sql);
header("location: ?page=message");
Yeah i know i am not using prepared statements, but i made that code just for testing purposes. Okay, it works. In the database i see
<script>top.location.href = "?page=message";</script>
So in that message page i see the post that was just inserted. But i don't see the effect of htmlspecialchars? It affected the post when it got submitted to the database, but when i display it in the message page.. i see again
<script>top.location.href = "?page=message";</script>
Any idea why this is happening? Is the htmlspecialchars command only meant to be for output?