Special character escaping issue

Hello,
          I want to escape the special characters (eg: ' , " etc) from a string before inserting to the database and to show it in original form while retrieving  from the database. I tried with htmlentities, but I couldn't see any change in the data. Do I need to modify anything on the server for working htmlentities?
JacobbabyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

InsoftserviceCommented:
A technically inaccurate comment was deleted.
0
dimmergeekCommented:
To escape special characters:

$fname = mysqli_real_escape_string($dbconn, trim($_POST["element"]));

Open in new window


To re-display them in HTML:

stripslashes($yourvariable)

Open in new window

0
Ray PaseurCommented:
Here is an article that answers this question and much more about using PHP with data base extensions.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

InsoftserviceCommented:
@ dimmergeek It will work only if he is using mysql.
What about oracle or any other DB.

so first we have to be clear with db
0
Ray PaseurCommented:
I think @dimmergeek is pointing in the right direction.  See #19 and #21 in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12293-AntiPHPatterns-and-AntiPHPractices.html

If the DB is not MySQL, there are different escape sequences for quotes and nulls, but the concept is the same.  See also the risks of Magic Quotes.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_6630-Magic-Quotes-a-bad-idea-from-day-one.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JacobbabyAuthor Commented:
ok thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.