[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • 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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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