I made a page where users are able to edit text that goes straight into my SQL database. The problem however is that SQL ignores new lines in the HTML textarea. For example, when I type:
- 1
- 2
- 3
It shows "123" when I run a SELECT query. How can I adjust the code so SQL does not ignore new lines in the textarea?
<?php
session_start();
if (!isset($_SESSION['ingelogd'])
|| $_SESSION['ingelogd'] !== true) {
header('Location: /xxxx/xxxx/Login.php');
exit;
}
?>
<CSS code removed>
<?php
function sanitize($data) {
return stripslashes(strip_tags(mysql_real_escape_string(htmlentities($data))));
}
if (isset($_POST)) {
if (!empty($_POST["inhoud"])) {
$con=mysqli_connect("localhost","root","","db1");
if (mysqli_connect_errno($con))
{
echo "Database error: " . mysqli_connect_error();
}
$sanitize_post = $_POST["inhoud"];
$sanitize_post = sanitize($sanitize_post);
mysqli_query($con,"UPDATE tekstpagina SET inhoud='$sanitize_post' WHERE naam='over'");
mysqli_close($con);
}
}
?>
<b>Update:</b>
<form action="" method="post"><br><textarea id="styled" name="inhoud"></textarea>
<br/><input type="submit" value="Bijwerken" name="Update">
</form>
</p>