Data read from MySQL, posted into textbox truncates at apostrophe

I am reading data from MySQL into a form built in PHP so I can edit it. This is READ and not WRITE. When I post the data into a text box anything with an apostrophe truncates the data at the apostrophe. I have searched and read and can’t find anything addressing this issue. There’s lots on the un-sanitized writing to MySQL but not this issue. Any suggestions would be greatly appreciated.

            echo  "<form id='modify' name='modify' method='post' action='modify.php'>";            
            echo "Artist:  " . "<input type='text' name='partist' size='40' autofocus tabindex='1' value='". $record['artist'] ."'/><br>";                    
            echo "Title:  " . "<input type='text' name='ptitle' size='50' tabindex='2' value='". $record['title'] ."'/><br>";

The code goes on for another 22 fields but these are the only ones with apostrophes.

Hi Jim,

The problem is that you’re using single quotes for your element attributes, and so the single quote in your data is terminating the value attribute prematurely, truncating the text.

To fix it, you can enclose your PHP output in single quotes and use double quotes for your HTML attributes:

echo 'Artist:  <input type="text" name="partist" size="40" autofocus tabindex="1" value="'. $record['artist'] .'" /><br>';
1 Like

Thank you so much @fretburner. I never would have thought of that. I “borrowed” the syntax off of a YouTube video. I guess you can’t believe everything you read on the net! [Grin]

Works perfectly. Thanks for solving an issue that’s been driving me nuts for about a week.