• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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?
0
mgtm3
Asked:
mgtm3
3 Solutions
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now