Insert textarea datas in mysql, with " or '....

This is a discussion on Insert textarea datas in mysql, with " or '.... within the PHP Language forums, part of the PHP Programming Forums category; I've a textarea and would like to save the content in a mysql table each time a user click ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-13-2004
Bob Bedford
 
Posts: n/a
Default Insert textarea datas in mysql, with " or '....

I've a textarea and would like to save the content in a mysql table each
time a user click on a form.

How can I do for avoiding error when the user put a " or a ' in the message,
or any other character that may cause problems.

My query is:
"insert into questions(UserID,Question) values
(".$HTTP_POST_VARS["USERID"].",'".$HTTP_POST_VARS["QUESTION"]."')"

The problem is with QUESTION, that may have a ' in it, or ".

Bob


Reply With Quote
  #2 (permalink)  
Old 10-13-2004
Harrie Verveer
 
Posts: n/a
Default Re: Insert textarea datas in mysql, with " or '....

"insert into questions(UserID,Question) values
(".$HTTP_POST_VARS["USERID"].",'".mysql_escape_string($HTTP_POST_VARS["QUESTION"])."')"

this will work for single quotes and double quotes, but not for
`backquotes`. Most of the time I think people just shouldn't insert
backquotes :) So I normally just replace backquotes with single quotes
and the problem is solved:

"insert into questions(UserID,Question) values
(".$HTTP_POST_VARS["USERID"].",'".mysql_escape_string(str_replace("`","'",$HTT P_POST_VARS["QUESTION"]))."')"

not tested but should work :)


Bob Bedford wrote:
> I've a textarea and would like to save the content in a mysql table each
> time a user click on a form.
>
> How can I do for avoiding error when the user put a " or a ' in the
> message, or any other character that may cause problems.
>
> My query is:
> "insert into questions(UserID,Question) values
> (".$HTTP_POST_VARS["USERID"].",'".$HTTP_POST_VARS["QUESTION"]."')"
>
> The problem is with QUESTION, that may have a ' in it, or ".
>
> Bob
>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:50 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0