i got a an error when i am trying to insert something into mysql using php

this is the error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Day','Valentine's Day','Favorite holiday?','other')' at line 1


what is that?
mgtm3Asked:
Who is Participating?
 
michofreihaCommented:
Use \ before the single quote

'Valentine\'s Day'
0
 
gamebitsCommented:
Not seeing the whole query it's hard to say but my guess is you are not ecaping the ' in 'Valentine's Day' try it with 'Valentine\'s Day' and any other one like that.
0
 
mgtm3Author Commented:
is there no other whay
because i am getting this from a text field and then i am using post action to get it
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
michofreihaCommented:
I don't think so...
0
 
gamebitsCommented:
Use mysql_real_escape_string function

http://ca3.php.net/mysql_real_escape_string
0
 
afzzCommented:
Use the insert query as follows:
addslashes will add / to any posted values containing quotes

similarly you can use stripslashes($var) to remove the slashes added above

HTH,
AK
foreach($_POST as $key => $val){
$_POST[$key] = addslashes($val);
}
insert into table values('.$_POST['str1'].','.$_POST['str1'].','....and so on...','.$_POST['last'].');

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.