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 08 '25
This is how it works: You open Dev tools, then click on the Network tab. Then post your form. In the network tab there will be one or more rows. Click on one with POST method. And then in the Payload section you will see your data sent. Paste it here.
You need to follow the data all the way from HTML form to database, to find the place where slashes get added