I am creating a forum with PHP and MySQL with the help of PDO class. I have just started coding the forum and come up with a problem.
What I am doing is that
$post_body = htmlentities($_POST['post_body']);
get the user input like this and then send this to my function that then query this into the database like this
$str = $this->database->prepare('INSERT INTO `blah`,`blah_blah` VALUES(?,?)');
$str->bindValue(1,$someVal);
$str->bindvalue(2,$post_body);
$str->execute();
and when I display these details i do something like this
html_entity_decode($postDetails['post_body']); //$postDetails has been initialized correctly
Yes I have added try catches and handled the exceptions; but since this is a forum post, when a user presses return key, he/she expects to have a new line in the posted article. but when i display these posts i am losing every return/new lines in the post. Why and how do I get around this.
Explanation about wht this happens would be much appreciated!
Thanks in advance.
is not an html entity. It will not be decoded by that function.
Use nl2br
to accomplish this like so:
echo nl2br(html_entity_decode($postDetails['post_body']))