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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:41:38+00:00 2026-06-08T21:41:38+00:00

Possible Duplicate: The ultimate clean/secure function I have run into a few problems with

  • 0

Possible Duplicate:
The ultimate clean/secure function

I have run into a few problems with some of my coding, I have unwillingly uncovered a possible sql injection in my script and I can’t seem to resolve the issue, so I wondered if anyone from around here could help out with it.

Can I just say I am fine coding my scripts, its just I have absolutely no idea how database injections happen, how they work or how to prevent them, however it is quite clear my cleaning function does not work as intended.

Here is the offending chunk of code, when I add the following after id it will spit out a MySQL error, which I have read alot about that meaning my code is vulnerable.

&id=369';

So just adding a comma and a semi-colon breaks the MySQL query, that isn’t desired. Here is the code that handles the query and displays the data;

$id = $this->clean($_GET['id']);
#$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_STRING);
$pm_query = mysql_query("SELECT * FROM `staff_pm` WHERE `id` = '{$id}' AND `status` IN(0, 1)") or die(''.mysql_error());

So I have tried one of the integrated functions within PHP but that spits out the same sql error, this is my cleaning function which I was told beforehand was fine:

function clean( $str )
{
return mysql_real_escape_string( htmlspecialchars( trim( $str ) ) );
}

Just really wanted to know your opinions on the matter, it is a constant worry that my coding will be taken advantage of by a person who is looking for these types of vulnerabilities, and I really want to make sure it is up to scratch and learn some techniques to better protect it.

I have been told to convert to PDO, however it seems like a large job converting and I will wait until I come to re-creating the application before I do that, where I am going to go for a much more object-orientated approach.

The SQL error I receive is this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘\’; AND status IN(0, 1)’ at line 1

Thank you for any help, I really do appreciate it.

Regards

  • 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-08T21:41:40+00:00Added an answer on June 8, 2026 at 9:41 pm

    I’d also recommend not using the obsolete mysql_* functions and instead use PDO.

    But to fix your existing code, use intval.

    $id = intval($_GET['id']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP: the ultimate clean/secure function I have got this code when I
Possible Duplicate: The ultimate clean/secure function After reading up on PHP security I have
Possible Duplicate: The ultimate clean/secure function I was informed in another thread that this
Possible Duplicate: PHP: the ultimate clean/secure function I am working on an experimental social
Possible Duplicate: The ultimate clean/secure function When it comes to sanitizing POST/GET data could
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: What is the ultimate postal code and zip regex? I need Regex
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always

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.