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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:33:02+00:00 2026-05-16T08:33:02+00:00

PHP: $SQL = SELECT goodies FROM stash WHERE secret=’ . str_replace(‘,”,$_POST[‘secret’]) . ‘; Could

  • 0

PHP:

$SQL = "SELECT goodies FROM stash WHERE secret='" .  
    str_replace("'",'',$_POST['secret']) .  
"'";  

Could an evil genius hacker inject SQL into my SELECT – How ?

  • 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-16T08:33:03+00:00Added an answer on May 16, 2026 at 8:33 am

    I’ve had a think about this for a while and I can’t see any way to inject SQL into this statement.

    An SQL string that starts with a single quotes terminates at the next single quote unless it is escaped with a backslash or another quote (\' or ''). Since you are removing all single quotes there cannot be a doubled quote. If you escape the closing quote you will get an error, but no SQL injection.

    However this method has a number of drawbacks:

    • Single quotes in the input are ignored.
    • Backslashes in the input aren’t handled correctly – they will be treated as escape codes.
    • You get an error if the last character is a backslash.
    • If you later extend the query to add a second parameter, it would allow an SQL injection attack.

    For example:

    $SQL = "SELECT goodies FROM stash WHERE secret='" .  
        str_replace("'",'',$_POST['secret']) .  
    "' AND secret2 = '" .
        str_replace("'",'',$_POST['secret2']) .  
    "'";  
    

    When called with parameters \ and OR 1 = 1 -- would result in:

    SELECT goodies FROM stash WHERE secret='\' AND secret2=' OR 1 = 1 -- '
    

    Which MySQL would see as something like this:

    SELECT goodies FROM stash WHERE secret='...' OR 1 = 1
    

    Even if it’s impossible to cause an injection in this case the drawbacks make this unsuitable for a general purpose way to avoid SQL injection.

    The solution, as already pointed out, is to use a prepared statement. This is the most reliable way to prevent SQL injection attacks.

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

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would normally use set define off as suggested by… May 16, 2026 at 6:56 pm
  • Editorial Team
    Editorial Team added an answer When you use lazy loading, you should always use the… May 16, 2026 at 6:56 pm
  • Editorial Team
    Editorial Team added an answer var result = new Collection<string>(collection1.Concat(collection2).ToList()); For some reason System.Collections.ObjectModel.Collection requires… May 16, 2026 at 6:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I've got the following MySQL query: <?php $sql = SELECT * FROM my_table; $result
I have this php query $sql = SELECT * FROM db; $query = mysql_query($sql);
<?php $sql = mysql_query(SELECT body FROM comments); while ($r = mysql_fetch_assoc($sql)) { $body .=
I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
<?php $sql = " SELECT e.*, l.counts AS l_counts, l.date AS l_date, lo.counts AS
IS this bit of code in PHP/mysql considered a stored procedure? $sql = 'SELECT
How best to alter a SQL SELECT statment's field list to a COUNT(*) using
What I'm trying to do is run the same SQL select on many Oracle
I'm new to php and sql. I have a table with three columns. One
I noticed that a lot of tutorial instructions often have this code: $sql=SELECT *

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.