r/PHPhelp • u/danlindley • Aug 07 '25
Backslashes viewable with php echo
I promise i have read around prior to posting but I i just don't get how to make this work. I've tried reading and experimenting with htmlspecialchars, htmlentities,and mysql_real_escape_string but its not going in and can't figure out to get things "human legible" (i.e. no ampersand and apos or \' )
<?php
/*----------------------- FORM PROCESSING Update casualty details-------------------*/
//Check if the update was submitted
if (isset($_POST['notesupdate'])) {
$notes = $_POST["notes"];
try {
$statement = $conn->prepare("UPDATE tbl_notes
SET
tbl_notes.note = :note
WHERE
note_id=:note_id");
$statement->execute([
'note_id' => $note_id,
'note' => $notes
]);
echo "<script>window.location = window.location</script>";
} catch (PDOException $e) {
echo "Database Error: Could not update the notes.<br>" . $e->getMessage();
exit();
} catch (Exception $e) {
echo "General Error: Could not update the notes.<br>" . $e->getMessage();
exit();
}
}
/*------------ END FORM ----------------*/
?>
<div class="card-header">
<form action="" method="post" id="">
<strong>Notes</strong>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm px-md-5" >
<textarea id="notes" name="notes" rows="40" cols="50">
<?php echo htmlspecialchars($cas_notes); ?></textarea>
<input type="submit" name="notesupdate" value="Save" class="btn btn-success">
</form>
</div>
</div>
</div>I have the LONGTEXT field to store the notes in the database. Each time I submit anything with ' or " it is converted and stored in the database as \' or ' depending on the method used.
Ideally I'd like to be able to store this information "safely" and subsequently return it to the user legibly. I'm not sure why it is different on this field but it isn't playing nice.
Thanks
DAn
View all comments
Show parent comment
1
u/colshrapnel Aug 07 '25
Php code gets executed from top to bottom. We don't need "other pages". We need to see entire code, from the very first line, that gets executed when these notes are shown. That code you posted above, obviously not complete. We need to see the complete code.