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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing apostrophe in form 1

Status
Not open for further replies.

LWolf

Programmer
Feb 3, 2008
77
US
I have a problem passing an ' in a select option. The database values have the ' so I need to pass it but the value that gets passed stops after the apostrophe.
For example...

My code is... <option value="Mac's">Mac's</option>

The page is...<option value='Mac's'>Mac's</option>

So when I submit the form the value that gets passed is "Mac". How can I pass the apostrophe?

Thanks in advance
K
 
the page will have the same code as yours. so if you send the single quote enquoted by double quotes then that is how the page will receive it and the form will be handled.

Thus any of these will work

Code:
echo "<option value=\"Mac's\">Mac's</option>";
echo '<option value="Mac\'s">Mac\'s</option>";
echo "<option value='Mac\'s'>Mac's</option>";
echo <<<HTML
<option value="Mac's">Mac's</option>
HTML;

remember that you will need to escape apostrophe's before using them in a database query and remember also to disable magic-quotes both at runtime and on get/post/cookie transactions.
 
$value_var = stripslashes ($value_var);
Use to remove slash to display data on a web page.


$value_var = addslashes ($value_var);
Use to add the slash back to put data to a database. The slash is used to escape the apostrophe otherwise the apostrophe signifies end of the string and you only get Paul in the database instead of Paul's
 
avoid addslashes/stripslashes. use database specific escaping methods instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top