Forum Moderators: coopster
Correctly echo'd as O\'Brien
However, the form:
echo "
<td style='color:red; font-weight: bold;'>*** Last Name: ***<br/><input type='text' name='lastname' tabindex='7' value ='".$lastname."' style='background-color:#FFFF99; width:100%;'> ";
just displays O\
Any ideas why?
Thanks
I know it's escaped correctly as the SQL query works but somehow the apostrophe is messing up the string when I try to put it back into an input box.
These are submitted (POST) and validated.
In the example above they are fine and are put in the database. With browse they appear as John O'Brien
i.e. with apostrophe correctly.
No data is actually retrieved from the database ever.
So what happens is, for example
Input box 1:J
Input Box 2:O'Brien
This is submitted (POST) and validated. My script sees that Input box 1 is less than 2 characters long so instead of inserting the data it just brings up a message highlighting input box 1.
For user friendly stuff, I fill in input box 2 for them automatically. So, it's supposed to read O'Brien except it only reads O\
So, howcome if the form was all fine, the database entry works fine, but the default value for the input box stops at O\?
I checked the variable just before it is echod for the input box and it display O\Brien.
Thefore the bit where I put <input blah blah value='".$lastname."'
Something in that stops as soon as it gets to the apostrophe
You could after checking data such as passing through your regex and if isset and!empty
Use the post value to create a session then exit() if check does not pass.
Pass it back to the form and unset and destroy it
Now the value is preserved but only if data is OK.
When all users’ inputs are OK write to your DB.
And for edit purpose if needed use another set of form
echo "
<td style='color:red; font-weight: bold;'>*** Last Name: ***<br/><input type='text' name='lastname' tabindex='7' value ='".stripslashes($lastname)."' style='background-color:#FFFF99; width:100%;'> ";