So, I've got a form that enters into a database and those values are then echoed on the page. I have been trying to figure out how to disable all code from being processed when put through the form.
This is my form:
<div id="postForm">
<form method="post" action="post.php" id="messageForm" autocomplete="off">
<table border="0" align="center">
<tr><td id="formBlock"><span>Name</span></td>
<td><input id="messageName" name="name" type="text" value="Anonymous" maxlength="32" required>
<input style="margin-right: -1px; margin-left: -4px;" type="submit" name="Submit" value="Send Message"></td></tr>
<tr><td id="formBlock"><span>Title</span></td>
<td><input id="messageTitle" name="title" type="text" maxlength="32" width="20"></td></tr><br>
<tr><td id="formBlock"><span>Message</span></td>
<td><textarea onkeyup="countChar(this)" name="message" rows="6" cols="50" form="messageForm" maxlength="2000" style="font-family: arial;" required></textarea></td></tr>
</table>
</form>
<table align="center" style="width: 290px; border: 0px;">
<td><div id="warningText" style="font-size: 10px; margin-top: -15px;">Please read the FAQ before posting!</div></td>
<td><div id="messageText" style="font-size: 10px; margin-top: -15px; text-align: right;"></div></td>
</table>
</div>
And this is how the entries are being echoed:
<div id="messages">
<?php
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db_posts";
$tablename = "posts";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("failed to connect: " . $conn->connect_error);
}
$sql = "SELECT id, rating, name, title, message, date, time FROM posts ORDER BY date DESC, time DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<br><div id='messageBar'><b><a class='rateup' href='index.php' data-id=' " . $row['id'] . " ' title='vote up'>▲</a> ";
echo $row["rating"];
echo " <a class='ratedown' href='index.php' title='vote down'>▼</a> </b>";
echo "Posted by <b>";
echo $row["name"];
echo "</b> on ";
echo $row["date"];
echo " at ";
echo $row["time"];
if (!empty($row['title'])) {
echo " - <b>";
echo $row["title"];
echo "</b>";
}
echo "<span style='float: right'>#";
echo $row["id"];
echo "</span>";
echo "</div><div id='messageContent'>";
echo $row["message"];
echo "</div><br><hr>";
}
} else {
echo "<br>";
echo "<center><i>it's dusty in here</i></center>";
echo "<br>";
}
$conn->close();
?>
</div>
I'm sure that there's a better way I can echo all of this data, so if anyone has any suggestions feel free to let me know.
TL;DR: If someone enters <b>text</b>
into my form, I want it to echo like <b>text</b>
.