• 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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