Re: ' giving problem while inserting in table.
| From: | Lars Olsson | Date: | Tue, 16 Jul 2002 15:40:54 +0000 |
| Subject: | Re: ' giving problem while inserting in table. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-107909@lists.php.net to get a copy of this message | ||
Since ' is a string delimiter in MySQL it has to be escaped. Try using mysql_escape_string($string) (http://se.php.net/manual/en/function.mysql-escape-string.php) on all the strings before you try to insert them into MySQL.
/lasso (lasso@lassoweb.nu)
Anil Garg wrote:
Hi, I am making a faq maintenance system using mysql and php. To insert a entry in to a faq table i am using the following query: --------- INSERT INTO faq_table_netvd (id,question, answer,netvcr,netdetector,add_date,mod_date,keyword,category,display,attach_ id) VALUES ('0','$frm[question]', '$frm[answer]','$frm[netvcr]','$frm[netdetector]','$frm[add_date]','$frm[mod _date]','$frm[keyword]','$frm[category]','$frm[display]','$frm[attach_id]') "); ----------- now the problem is when $frm[question] has some string like: "why i can't eat". i get the following error: MySQL Error: You have an error in your SQL syntax near 't eat?' ,answer = 'Please recheck the power of your specs:)' ' at line 3.Putting a '\' before ' (e.g. \')solves my problem...but when i open the same quesion to edit it, again i have to put backslashes where ever i find " ' " in the quesion or answer. Can anyone please suggest a solution to this. thanx and regards anil [please ask if i havent explained the problem fully]