Solved

how can i escape apostrophe in mysql

Posted on 2010-08-22
3
724 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 500 total points
ID: 33496334
just an update..

you may also do so..


$cleanstring = mysql_real_escape_string($yourstring);
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now