Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8369571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:40:58+00:00 2026-06-09T13:40:58+00:00

I am trying to figure out which functions are best to use in different

  • 0

I am trying to figure out which functions are best to use in different cases when inputting data, as well as outputting data.

When I allow a user to input data into MySQL what is the best way to secure the data to prevent SQL injections and or any other type of injections or hacks someone could attempt?

When I output the data as regular html from the database what is the best way to do this so scripts and such cannot be run?

At the moment I basically only use

mysql_real_escape_string(); 

before inputting the data to the database, this seems to work fine, but I would like to know if this is all I need to do, or if some other method is better.

And at the moment I use

stripslashes(nl2br(htmlentities())) 

(most of the time anyways) for outputting data. I find these work fine for what I usually use them for, however I have run into a problem with htmlentities, I want to be able to have some html tags output respectively, for example:

<ul></ul><li></li><bold></bold> 

etc, but I can’t.

any help would be great, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:40:59+00:00Added an answer on June 9, 2026 at 1:40 pm

    I agree with mikikg that you need to understand SQL injection and XSS vulnerabilities before you can try to secure applications against these types of problems.

    However, I disagree with his assertions to use regular expressions to validate user input as a SQL injection preventer. Yes, do validate user input insofar as you can. But don’t rely on this to prevent injections, because hackers break these kinds of filters quite often. Also, don’t be too strict with your filters — plenty of websites won’t let me log in because there’s an apostrophe in my name, and let me tell you, it’s a pain in the a** when this happens.

    There are two kinds of security problems you mention in your question. The first is a SQL injection. This vulnerability is a “solved problem.” That is, if you use parameterized queries, and never pass user supplied data in as anything but a parameter, the database is going to do the “right thing” for you, no matter what happens. For many databases, if you use parameterized queries, there’s no chance of injection because the data isn’t actually sent embedded in the SQL — the data is passed unescaped in a length prefixed or similar blob along the wire. This is considerably more performant than database escape functions, and can be safer. (Note: if you use stored procedures that generate dynamic SQL on the database, they might also have injection problems!)

    The second problem you mention is the cross site scripting problem. If you want to allow the user to supply HTML without entity escaping it first, this problem is an open research question. Suffice to say that if you allow the user to pass some kinds of HTML, it’s entirely likely that your system will suffer an XSS problem at some point to a determined attacker. Now, the state of the art for this problem is to “filter” the data on the server, using libraries like HTMLPurifier. Attackers can and do break these filters on a regular basis; but as of yet nobody has found a better way of protecting the application from these kinds of things. You may be better off only allowing a specific whitelist of HTML tags, and entity encoding anything else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to figure out which to use.
I'm trying to figure out the best option to use anonymous event listeners that
I am trying to figure out what is the best workflow to use Git
I am trying to figure out explicitly which of the functions in SciPy/NumPy run
I'm trying to figure out how and which is best for storing and getting
I am trying to figure out exactly how to implement a callback function which
I am trying to figure out which is most appropriate. From the articles I
I'm trying to figure out a way to find out which files were affected
Just out of curiosity, I'm trying to figure out which exactly is the right
I am trying to automatically figure out which Delphi version (of Delphi 5 to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.