I am escaping data prior to DB insertion using: $entry = mysqli_real_escape_string($link, $value);
and then using htmlspecialchars()
on the output before displaying, however in my output I appear to have slashes within the string, as in It\'s not working
. Obviously I don't want that.
Code (abbreviated for simplicity):
function insertData($post)
$dbc = mysqli_connect(DB_HOST, DB_UN, DB_PW, DB_NAME);
foreach ($post as $key => $value) {
$post[$key] = mysqli_real_escape_string($dbc, $value);
}
$insert = 'INSERT INTO products_test ('.array_keys($entry)[0].','.array_keys($entry)[1].') VALUES ("'.array_values($entry)[0].'","'.array_values($entry)[1].'")';
if (mysqli_query($dbc, $insert)) {
echo htmlspecialchars($post['name']).' has been added to the inventory';
}
$post = [
'name' => $_POST['name'],
'narrative' => $_POST['narrative']
];
insertData($post);