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 663841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:32:01+00:00 2026-05-13T23:32:01+00:00

Is mysql_real_escape_string sufficient for cleaning user input in most situations? ::EDIT:: I’m thinking mostly

  • 0

Is mysql_real_escape_string sufficient for cleaning user input in most situations?

::EDIT::

I’m thinking mostly in terms of preventing SQL injection but I ultimately want to know if I can trust user data after I apply mysql_real_escape_string or if I should take extra measures to clean the data before I pass it around the application and databases.

I see where cleaning for HTML chars is important but I wouldn’t consider it necessary for trusting user input.

T

  • 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-13T23:32:02+00:00Added an answer on May 13, 2026 at 11:32 pm

    mysql_real_escape_string is not sufficient in all situations but it is definitely very good friend. The better solution is using Prepared Statements

    //example from http://php.net/manual/en/pdo.prepared-statements.php
    
    $stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (?, ?)");
    $stmt->bindParam(1, $name);
    $stmt->bindParam(2, $value);
    
    // insert one row
    $name = 'one';
    $value = 1;
    $stmt->execute();
    

    Also, not to forget HTMLPurifier that can be used to discard any invalid/suspicious characters.

    ………..

    Edit:
    Based on the comments below, I need to post this link (I should have done before sorry for creating confusion)

    mysql_real_escape_string() versus Prepared Statements

    Quoting:

    mysql_real_escape_string() prone to
    the same kind of issues affecting
    addslashes().

    Chris Shiflett (Security Expert)

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

Sidebar

Related Questions

Im using smarty and mysql_real_escape_string() for user input, and when I insert some code
mysql_real_escape_string is used for SQL statements. Is it enough for database security alone? For
mysql_real_escape_string and addslashes are both used to escape data before the database query, so
if (isset($_POST['login'])) { $query = mysql_query(" SELECT id FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."'
MySQL has this incredibly useful yet proprietary REPLACE INTO SQL Command. Can this easily
Considering that everyone is always worried about User Data (And Rightly So), would it
Is mysql_real_escape_string() with sprintf needed only at login page or at every mysql_query after
Is mysql_real_escape_string supposed to replace both addslashes() and stripslashes()?? ie.. do I use it
$tag = mysql_real_escape_string($_GET['tag']); $tag = str_replace("-", " ", $_GET['tag']); $query = mysql_query("SELECT * FROM
I'm using mysql_real_escape_string to escape my content but I am receiving an error in

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.