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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:40:11+00:00 2026-05-24T15:40:11+00:00

As I was learning from couple of years old tutorials I have end up

  • 0

As I was learning from couple of years old tutorials I have end up with following code which IS vulnerable for SQL injections.

Can someone explain to me how to work with mysql_real_escape_string()?
Is this currently bulletproof method?

//Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
    $str = @trim($str);
    if(get_magic_quotes_gpc()) {
        $str = stripslashes($str);
    }
    return mysql_real_escape_string($str);
}

//Sanitize the POST values
$usr = $_SESSION['usr'];
$live = (isset($_POST['live']))?1:0;
$created = date("F j, Y, g:i a",time()+60*60);
$title= clean($_POST['title']);
$content = clean($_POST['content']);

//Create INSERT query
$qry = "INSERT INTO news( usr, live, created, title, content) VALUES( '$usr', '$live', '$created', '$title', '$content') ";
$result = @mysql_query($qry);
  • 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-24T15:40:12+00:00Added an answer on May 24, 2026 at 3:40 pm

    Yes, it is. In this case.

    Note there is nothing like “universal sanitization”. Let’s call it just quoting, because that’s what its all about.

    When quoting, you always quote text for some particular output, like:

    1. string value for mysql query
    2. like expression for mysql query
    3. html code
    4. json
    5. mysql regular expression
    6. php regular expression

    For each case, you need different quoting, because each usage is present within different syntax context. This also implies that the quoting shouldn’t be made at the input into PHP, but at the particular output! Which is the reason why features like magic_quotes_gpc are broken (I recommend to keep it switched off).

    So, what methods would one use for quoting in these particular cases? (Feel free to correct me, there might be more modern methods, but these are working for me)

    1. mysql_real_escape_string($str)
    2. mysql_real_escape_string(addcslashes($str, "%_"))
    3. htmlspecialchars($str)
    4. json_encode() – only for utf8! I use my function for iso-8859-2
    5. mysql_real_escape_string(addcslashes($str, '^.[]$()|*+?{}')) – you cannot use preg_quote in this case because backslash would be escaped two times!
    6. preg_quote()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning Hibernate from the tutorials on JBoss website. I have a confusion
I have just started learning MVVM. I've made the application from scratch by following
From couple of days, I have started working/learning the backbone.js . I have read
I hope you guys have time for an old dog (71 years old) learning
I have been here for a couple of months learning python from examples, but
in the book i'm learning from i came across this code snippit: while (i
I am learning MVC from Stephen Walther tutorials on MSDN website. He suggests that
I am learning JPA from this tutorial . I have some confusions in understanding
I'm learning C++ from scratch, and as such I don't have an expert understanding
Can you refer me to a good starting place for learning GAE from what

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.