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

Posted on 2008-06-10
Last Modified: 2008-06-10
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?
Question by:mgtm3
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

michofreiha earned 167 total points
ID: 21749613
Use \ before the single quote

'Valentine\'s Day'
LVL 28

Expert Comment

ID: 21749616
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.

Author Comment

ID: 21749620
is there no other whay
because i am getting this from a text field and then i am using post action to get it
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Expert Comment

ID: 21749634
I don't think so...
LVL 28

Assisted Solution

gamebits earned 167 total points
ID: 21749641
Use mysql_real_escape_string function

Assisted Solution

afzz earned 166 total points
ID: 21749689
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

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


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change Wording in Wordpress Plugin 4 32
What is key combo for a b with a forward slash through it? 12 58
SSL unsecure page mystery 17 38
Load string Array from file 23 36
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question