I am trying to learn and better understand how to properly prevent sql injection and properly extract database information to show in a website.
I am currently using mqli_real_escape_string but the problem is when I extract the data there is a slash where the user may have entered an apostrophe or a quote, such as O'Connell, etc...
If I use a function to remove slashes, it defeats the purpose of using the mqsli_real_escape_string.
What is the proper way to prevent injection while allowing usage of apostrophes where necessary?
MySql
$name = mysqli_real_escape_string($link, $_POST['commentName']);
$comment = mysqli_real_escape_string($link, $_POST['commentMessage']);
$BID = mysqli_real_escape_string($link, $_POST['BID']);
HTML/PHP
<div class="uname"><?php echo $name ?></div>
<div class="comment"><p><?php echo $comment ?></p></div>