0

Simply put, the apostrophes are not displaying inside my text field. The result is here: www.unidrones.co.za/VRentals

In the search box, try typing something with an apostrophe like 1920's car or something. You will see a new form that appears. The "Model" field is supposed to accept the exact same string the user typed.

I viewed this nearly duplicate question: The apostrophes are not displayed when getting data from MySQL into bootstrap table but in my case I am not getting my value from the database, I'm getting the value directly from the previous form the user submitted.

I've tried escaping the string, I've tried utf8_encode() and utf8_decode(), I've tried prepared statements and I even tried changing all the "POST" methods to "GET" methods to see if that made any difference. Yet still, if I tried searching for something like 1920's Chrysler the apostrophe would turn into a backslash and the rest of the sentence would be gone.

My code:

<form action='inc/request.inc.php' method='POST' class='request-form' id='request-form'>
            <label class='bold required'>Model</label>
            <input type='text' name='searchvalue' class='searchvalue' value='".mysqli_real_escape_string($conn, $_POST['search'])."' required >
            <label class='bold required'>Full Name</label>
        ...
        </form> 
J Doe
  • 111
  • 2
  • 11
  • Think about `mysqli_real_escape_string`. Look at the name. It is for MySQL. You aren't writing SQL for MySQL. You are writing HTML. – Quentin Jun 07 '18 at 21:34
  • @Quentin Yes I thought so, that's why initially I just used $_POST['search'] as the value, then I tried searching for something with an apostrophe and came across this issue. I never had an issue with HTML and apostrophes before so I'm pretty clueless why this is happening. – J Doe Jun 07 '18 at 21:37
  • 1
    You've got `value='something'` what would you expect to happen if you put a `'` in the middle of `something` given the `'` that are marking its edges? – Quentin Jun 07 '18 at 21:43
  • Ah that makes perfect sense... Your reference to the duplicate question really helped. Not much more I can do than say thanks with an upvote :) – J Doe Jun 07 '18 at 21:47

0 Answers0