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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:11:59+00:00 2026-06-18T04:11:59+00:00

Possible Duplicate: How to prevent SQL injection in PHP? Consider this snippet, *mysqltest.php* $user_id=

  • 0

Possible Duplicate:
How to prevent SQL injection in PHP?

Consider this snippet,

*mysqltest.php*

$user_id= $_GET['user_id'];
$user_id= mysql_real_escape_string($user_id);
$query  = "SELECT * FROM people WHERE uid=".$user_id;
echo $query;
//then execution ..

Now, when we call this script as “mysqltest.php?user_id=56 or 1”

The query would be,
SELECT * FROM people WHERE uid=56 or 1 and result in successful injection.

So how can we protect ourselves at such situations where the column is of numeric types?


Is there any other work arounds at these situations without using pdo or prepared statements?

  • 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-18T04:12:00+00:00Added an answer on June 18, 2026 at 4:12 am

    There are no “other issues” for the mysql_real_escape_string.

    Most people confuse this function, thinking it’s intended to protect them from injection by “cleaninig” somehow whatever “user input”.
    This is wrong for sure.
    mysql_real_escape_string intended to format strings, making them good for the SQL query. That’s all. As a side effect it makes injection impossible too.

    So, every time one is going to add a string into query dynamically, they have to follow both string formatting rules, no matter of the data source:

    • enclose the data in quotes
    • escape special characters in it

    as they are useless one without another.

    Though it’s all right to treat numbers as strings.
    So, for the given example you cat treat your data as a string, as it was suggested in the deleted answer

    $user_id= $_GET['user_id'];
    $user_id= mysql_real_escape_string($user_id);
    $query  = "SELECT * FROM people WHERE uid='$user_id'";
    

    the only exception is a LIMIT clause parameters that have to be integers only.
    the only solution in this case would be to cast the data to desired format manually

    $user_id= $_GET['user_id'];
    $user_id= intval($user_id);
    $query  = "SELECT * FROM people WHERE uid=$user_id";
    

    but remember, there are other cases, which require different treatment

    One more thing to add.
    It is boring to format your data manually.
    Much better to let some code to do it for you, making code both short and safe

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

Sidebar

Related Questions

Possible Duplicate: Best way to prevent SQL injection in PHP? This is a simple
Possible Duplicate: How can I prevent SQL injection in PHP? This is the example
Possible Duplicate: Best way to prevent SQL injection in PHP? This is my code
Possible Duplicate: Best way to prevent SQL Injection in PHP Is this code protected
Possible Duplicate: Best way to prevent SQL Injection in PHP Is this code secure
Possible Duplicate: How to prevent SQL injection in PHP? I have this code $where
Possible Duplicate: How to prevent SQL injection in PHP? I have a following MySQL
Possible Duplicate: Best way to prevent SQL injection in PHP? I've made a PHP
Possible Duplicate: Best way to prevent SQL injection in PHP? My html web form
Possible Duplicate: Best way to prevent SQL injection in PHP? I am building my

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.