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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:50:27+00:00 2026-05-27T05:50:27+00:00

We know that all user input must be escape by mysql_real_escape_string() function before executing

  • 0

We know that all user input must be escape by mysql_real_escape_string() function before executing on mysql in php script. And know that this function insert a \ before any ' or " character in user input. suppose following code:

$_POST['username'] = 'aidan';
$_POST['password'] = "' OR ''='";

// Query database to check if there are any matching users
$query = "SELECT * FROM users WHERE user='".mysql_real_escape_string($_POST['username']."' AND password='".mysql_real_escape_string($_POST['password']."'";

mysql_query($query);

// This means the query sent to MySQL would be:
echo $query;

this code is safe.

But I find out if user enters her inputs with hexadecimal format then mysql_real_escape_string() can not do any thing and user can execute her sql injection easily. in bellow 27204f522027273d27 is same ' OR ''=' but in hex formated and sql execute without problem :

$_POST['username'] = 'aidan';
$_POST['password'] = "27204f522027273d27";

// Query database to check if there are any matching users
$query = "SELECT * FROM users WHERE user='".mysql_real_escape_string($_POST['username']."' AND password='".mysql_real_escape_string($_POST['password']."'";

mysql_query($query);

// This means the query sent to MySQL would be:
echo $query;

But whether this is true and if answer is yes how we can prevent sql injection in this way?

  • 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-27T05:50:28+00:00Added an answer on May 27, 2026 at 5:50 am

    If you are using mysql_real_escape_string(), odds are you would be better served using a prepared statement.

    For your specific case, try this code:

    /*
    Somewhere earlier in your application, you will have to set $dbh
     by connecting to your database using code like:
    $dbh = new PDO('mysql:host=localhost;dbname=test', $DBuser, $DBpass);
    */
    
    $_POST['username'] = 'aidan';
    $_POST['password'] = "' OR ''='";
    
    $user = $_POST['username'];
    $password = $_POST['password'];
    
    // Query database to check if there are any matching users
    $query = "SELECT * FROM users WHERE user=? AND password=?";
    
    $stmt = $dbh->prepare($query);
    $stmt->bindParam(1, $user);
    $stmt->bindParam(2, $password);
    $stmt->execute();
    

    This does require you to use PDO for your database interaction, but that’s a good thing overall. Here’s a question discussing the differences between PDO and mysqli statements.

    Also see this StackOverflow question which is remarkably similar to yours and the accepted answer, from which I poached some of this answer.

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

Sidebar

Related Questions

We all know that you can overload a function according to the parameters: int
After all what I've read on this topic, I know that there is no
I have a List< int[] > myList, where I know that all the int[]
I know that technically all three ways below are valid, but is there any
For instance, I know that basically all languages that are object oriented based are
I know that to find all the .h files I need to use: find
as you all know that if we use flash object in web page in
We all know that RAW pointers need to be wrapped in some form of
We all know that commenting our code is an important part of coding style
We all know that having a good note taking tool is important as a

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.