I'm reading values from a table and displaying them in a form that can be changed updated by the user. The problem is every time I make an update a bunch of spaces are being added to each value in the table.
Here is the basic code:
function ReadHTML($str) {
return htmlspecialchars(stripslashes($str), ENT_QUOTES);
}
$query = "SELECT * FROM " . $table_name . " WHERE id = " . $row_id;
$result = mysqli_query ($connection, $query ) or die ("Database query failed: " . mysqli_error($connection));
$row = mysqli_fetch_assoc($result);
$q1 = ReadHTML($row['q1']);
When I display the values in the form it looks fine. But it's when I update the values that the spaces get added.
When I process the updates it looks something like this:
function mysqli_prep(&$connection, $value) {
$detagged = strip_tags($value);
$escaped = mysqli_real_escape_string($connection, $detagged);
return $escaped;
}
$q1 = mysqli_prep($connection, $_POST['q1'])
$query = "UPDATE my_form SET
q1='$q1'";
Can anyone see what I'm doing wrong?
HTML looks like this:
<textarea class="textarea form_textarea_field" name="comment_1" placeholder="Comments">
<?php if($saved_form == true) {echo $q1;} ?>
</textarea>
When I look at the DOM in my browser it looks like this:
<textarea class="textarea form_textarea_field" name="comment_1" placeholder="Comments">
" Test text "
</textarea>
But I never added those quotes or spaces and they don't appear in the display. Not sure if that's normal or a clue as to what's wrong.