Page 1 of 1
Problems with apostrophe in form text fields
Posted: Sat Sep 19, 2009 11:44 am
by edawson003
When I enter a text string into text field on my form that includes includes
', when I click submit, the entry in the field is appended to
/' on the front end and upon successful post submission
/' or
//' or
///' ...etc (you get the drift, right?) is inserted into my table. The system seems to add a / everytime an attempt is made to submit the form. "Why more that one form submit attempt?, you may ask", well I am also testing field validation errors for other fields on the form. So, what can I do to (1) prevent the data from being appended with
/' and (2) prevent the front end display of the previously entered value from being appended with
/'?
I enter "
Libby's" into the text field and I get "
Libby/'s"
FYI, previous entered values are retained with:
Code: Select all
<input type="text" name="textfield" maxlength="30" value="[color=#0000FF]<?php echo isset($_POST['transfat']) ? $_POST['transfat'] : ''; ?>[/color]" />
Any thoughts on why is this happening anyway?
Re: Problems with apostrophe in form text fields
Posted: Sat Sep 19, 2009 11:54 am
by jackpf
Looks like you have magic quotes turned on.
Re: Problems with apostrophe in form text fields
Posted: Sat Sep 19, 2009 12:13 pm
by edawson003
Awesome. Thanks for the clue. I googled it and found a lot of posts about this issue. Solutions provided ranged from contacting your host to editing some php.ini file. Found this on the bottom of someone string:
Code: Select all
<?php
if (get_magic_quotes_gpc()) {
$in = array(&$_GET, &$_POST, &$_COOKIE);
while (list($k,$v) = each($in)) {
foreach ($v as $key => $val) {
if (!is_array($val)) {
$in[$k][$key] = stripslashes($val);
continue;
}
$in[] =& $in[$k][$key];
}
}
unset($in);
}
?>
Don't aks me how it works, but it seems to work.
Re: Problems with apostrophe in form text fields
Posted: Sat Sep 19, 2009 12:16 pm
by jackpf
Or you could just put
in a htaccess file

Re: Problems with apostrophe in form text fields
Posted: Sat Sep 19, 2009 1:04 pm
by edawson003
I tried the .htacess approach and got 500 server error.
Followed the instructions at this link to create the .htacess file:
http://www.javascriptkit.com/howto/htaccess.shtml
Seems like I might have to contact my host if I want to .htaccess approach, unless I zigged when I should of zagged when I set this thing up.
Thanks though for the advise, at least I have one way to fix the issue until I get a handle on this .htaccess thing!
Re: Problems with apostrophe in form text fields
Posted: Sat Sep 19, 2009 3:42 pm
by jackpf
I copied that straight from my own htaccess file...so it must be something to do with your server.
Do htaccess files normally work?
For example:
if you create a htacces in your root dir with this in:
Code: Select all
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^blah$ /index.php
If you go to
http://yoursite.com/blah does it show your index.php file?
I'm thinking your server might have disabled htaccess files...or maybe just php flags. I suggest you try and ask them

Re: Problems with apostrophe in form text fields
Posted: Sun Sep 20, 2009 12:55 am
by edawson003
I'll test that. I actually contacted my host and they suggested I create a file named php.ini in the required directory and just add the line :
magic_quotes_gpc = Off
Seemed to work. Magic quotes are now off. But my form submissions with ' in a text value won't submit to my sql table. Now it display just fine but, just won't post. Do I need to apply stripslashes or something.
Re: Problems with apostrophe in form text fields
Posted: Sun Sep 20, 2009 6:41 am
by jackpf
No, you need to add them. Run all user supplied data used in queries through mysql_real_escape_string().
Re: Problems with apostrophe in form text fields
Posted: Sun Sep 20, 2009 1:59 pm
by edawson003
The mysql_real_escape_string() worked. Thanks!
Re: Problems with apostrophe in form text fields
Posted: Sun Sep 20, 2009 2:22 pm
by jackpf
No problem.