Forum Moderators: coopster

Message Too Old, No Replies

PHP Form Textarea Issue

textarea value returing /

         

kb0000

6:11 am on May 31, 2010 (gmt 0)

10+ Year Member



I have a form.
Say,there are two fields. One field with Textarea and other one with Input.
Whenever someones enters Hi How are you. I've been there i.e. a ' in the textarea and say there is some validation error in the form as a result form loads again with the values entered by the user.

In the textarea the value loads is i.e. Hi How are you. I\'ve been there i.e. with a \ in front of '.

How can i avoid this.

dreamcatcher

6:55 am on May 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



stripslashes [php.net]

dc

kb0000

7:25 am on May 31, 2010 (gmt 0)

10+ Year Member



I tried using it, but when the data goes in the database it shows an error.
PHP variable is $textarea.
When I first try checking it if it exists in database:
$qry="SELECT * FROM tablename WHERE columnname=\"$textarea\"";
It shows error in the case when it already contains " in the value of $textarea

penders

8:15 am on May 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think you still need the slashes (ie. backslash escapes) in place when querying your DB (for the same reason you are using slashes in your query string above). However, you need to stripslashes before outputting the value of the field back to the page (if slashes have been added).

Matthew1980

12:40 pm on May 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there kb0000,

Format the sql correctly too:-

$qry = "SELECT * FROM `tablename` WHERE `column_name` = '".$textarea."' ";

Now its formatted ok the request will work.

Cheers,
MRb