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

  • SEARCH
  • Home
  • 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 7417823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:46:19+00:00 2026-05-29T07:46:19+00:00

I am trying to put a general purpose function together that will sanitize input

  • 0

I am trying to put a general purpose function together that will sanitize input to a Mysql database. So far this is what I have:

function sanitize($input){
    if(get_magic_quotes_qpc($input)){

        $input = trim($input); // get rid of white space left and right
        $input = htmlentities($input); // convert symbols to html entities
        return $input;
    } else {

        $input = htmlentities($input); // convert symbols to html entities
        $input = addslashes($input); // server doesn't add slashes, so we will add them to escape ',",\,NULL
        $input = mysql_real_escape_string($input); // escapes \x00, \n, \r, \, ', " and \x1a
        return $input;
    }
}

If i understood the definition of get_magic_quotes_qpc(). This is set by the php server to automatically escape characters instead of needing to use addslashes().

Have I used addslashes() and mysql_real_escape_string() correctly together and is there anything else I could add to increase the sanitization.

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-05-29T07:46:20+00:00Added an answer on May 29, 2026 at 7:46 am

    htmlentities() is unnecessary to make data safe for SQL. It’s used when echoing data values to HTML output, to avoid XSS vulnerabilities. That’s also an important security issue you need to be mindful of, but it’s not related to SQL.

    addslashes() is redundant with mysql_real_escape_string. You’ll end up with literal backslashes in your strings in the database.

    Don’t use magic quotes. This feature has been deprecated for many years. Don’t deploy PHP code to an environment where magic quotes is enabled. If it’s enabled, turn it off. If it’s a hosted environment and they won’t turn off magic quotes, get a new hosting provider.

    Don’t use ext/mysql. It doesn’t support query parameters, transactions, or OO usage.

    Update: ext/mysql was deprecated in PHP 5.5.0 (2013-06-20), and removed in PHP 7.0.0 (2015-12-03). You really can’t use it.

    Use PDO, and make your queries safer by using prepared queries.

    For more details about writing safe SQL, read my presentation SQL Injection Myths and Fallacies.

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

Sidebar

Related Questions

I trying to put together an Android app that will take a picture and
I am trying to create a script in Python that will collect data put
I'm trying to follow the general consensus that it's best to put one's domain
We're trying to put together kiosk solution where we can charge people by hour
I'm trying to put together a comprehensive regex to validate phone numbers. Ideally it
I am trying to put some distributed caching into play, I'm using this indeXus.Net
I'm trying to put in an exception in my web.config so that one page
I am trying to put a requirement together for a new environment to consist
I'm new to both Ruby and programming in general. I've been trying to put
I'm trying to figure out what is the best general design for applications that

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.