Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Escaping quotes in a form field 1

Status
Not open for further replies.

jimoblak

Instructor
Joined
Oct 23, 2001
Messages
3,620
Location
US
I've got a form field that is filled with data from MySQL. The form is an editor of previously recorded data.

Code:
<INPUT name=changeTitle value=\&quot;$Row[Title]\&quot;>

I just realized that it does not work when someone uses quotation marks in their entry.

If the Title was &quot;My Fair Lady&quot; presentation, the HTML would look like:
Code:
<INPUT name=changeTitle value=&quot;&quot;My Fair Lady&quot; presentation&quot;>
This HTML results in a blank field because the browser sees 2 quotation marks next to each other.

If I change the PHP to:
Code:
<INPUT name=changeTitle value=$Row[Title]>
(removing the escaped quotation marks) then presentation does not appear in the text field.

Can anyone recommend a way around this? Should I simply deny the ability to use quotation marks when the data is first entered?

It seems that single quotes are fine. How do I replace double quotes with single quotes when the data is first entered? The following does not work...
Code:
$newTitle = preg_replace (&quot;\&quot;&quot;, &quot;\'&quot;, $_POST[newTitle]);

- - picklefish - -

Why is everyone in this forum responding to me as picklefish?
 
Wow - it's like those gearheads at PHP.net wrote the manual just for me. I feel special [bigsmile].

Thanks for the direction.

- - picklefish - -

Why is everyone in this forum responding to me as picklefish?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top