• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

Handling quotes with php forms

Hi Experts,
I'm working on a php form and having some trouble with handing quotes.

I realize it's probably not the best way to code it, but I've been wrapping the table elements of my form in print statements. This means that if I code:

print '<tr BGCOLOR="white"><td><INPUT TYPE="text" NAME="capFirst" SIZE=40></td>';
and the user enters: My name is "bob", the output will be "My name is" because the quotes are read as being an element of the code and essentially ignored.

I use addSlashes() when I'm handling the data to put it into my databases, etc but I'd like users to be able to enter both single and double quotes in their entry and have the program allow both (at least in the front end).

How do I do this? Any help is appreciated.
0
dm06tw
Asked:
dm06tw
  • 2
  • 2
1 Solution
 
steelseth12Commented:
try

htmlentities($yourdata,ENT_QUOTES) instead of addslashes
0
 
dm06twAuthor Commented:
I'm not actually "addslashing" it until I handle it... The form has 3 steps, they fill in the first step and on the second step it sets the default values in the text boxes to what they typed from the first. I addSlash it before inserting it into my database.

maybe that's a bad way of doing it?
0
 
steelseth12Commented:
You should use addslashes or mysql_real_escape_string before entering data in the database.

When you echo  the values you  got from the first set use htmlentities

for example ....

print '<input type="text" name="somefield" value="'.htmlentities($_POST["data_from_1s_setpt"],ENT_QUOTES) .'">';
0
 
dm06twAuthor Commented:
Works great!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now