?
Solved

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

Posted on 2008-06-10
6
Medium Priority
?
206 Views
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?
0
Comment
Question by:mgtm3
[X]
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
6 Comments
 
LVL 9

Accepted Solution

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

'Valentine\'s Day'
0
 
LVL 28

Expert Comment

by:gamebits
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.
0
 

Author Comment

by:mgtm3
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

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

Assisted Solution

by:gamebits
gamebits earned 668 total points
ID: 21749641
Use mysql_real_escape_string function

http://ca3.php.net/mysql_real_escape_string
0
 
LVL 4

Assisted Solution

by:afzz
afzz earned 664 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

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

801 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