Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how can i escape apostrophe in mysql

Posted on 2010-08-22
3
Medium Priority
?
737 Views
Last Modified: 2013-12-13
Hello i am facing a problem each entry have a " ' " apostrophe mysql update or insewrt is returing an error ! it can add it to the database so how can i escape it ! and fix the update or insert .
Thanks.
 
0
Comment
Question by:Styleminds
  • 2
3 Comments
 
LVL 30

Expert Comment

by:Brad Howe
ID: 33496155
Hi,

Why not use the mysql escape character ?

http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html

\'  A single quote (“'”) character.

You will take the string you want to insert and replace all (') with (\').

You could also just replace the apostrophes with ascii like such

$string = str_replace("'", "'", $string);

Cheers,
Hades666
0
 
LVL 4

Expert Comment

by:Frozenice
ID: 33496310
you simple do you so..

$string = htmlspecialchars($yourstring);


0
 
LVL 4

Accepted Solution

by:
Frozenice earned 2000 total points
ID: 33496334
just an update..

you may also do so..


$cleanstring = mysql_real_escape_string($yourstring);
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
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

782 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