Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
207 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 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