Special character escaping issue

          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?
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.

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

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

Open in new window

To re-display them in HTML:


Open in new window

Ray PaseurCommented:
Here is an article that answers this question and much more about using PHP with data base extensions.
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.

@ 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
Ray PaseurCommented:
I think @dimmergeek is pointing in the right direction.  See #19 and #21 in this article.

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.

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
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

From novice to tech pro — start learning today.