I have a text area that users add notes too. On the next page I use the $_POST[Comments]
to show what was typed. I have an edit button to go back and see what was typed and edit the notes but when I show the $_POST[Comments]
it shows everything up to an apostrophe.
Example:
Originally typed: Let's try this.
When Editing: Let
Now when I pass it to the server to do an SQL add I use the following function to protect against SQL injection
function keepSafe($value) {
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
if (!is_numeric($value)) {
$value = "'" . mysqli_real_escape_string($value) . "'";
}
return $value;
}
The following is what I use to format the input for SQL insertion.
$Comments = str_replace("\n","<br />",$_POST['CustComments']);
$Comments = keepSafe($_POST['Comments']);
I need to be able to see all of the apostrophes in the notes section when editing before submission. And I want to make sure that when I do submit it is a SQL injection prevented safe code.