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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:05:17+00:00 2026-05-16T02:05:17+00:00

Hey there, I’m doing some queries to a MySQL database that involves some user-input..

  • 0

Hey there, I’m doing some queries to a MySQL database that involves some user-input.. And I was wondering how to prevent injection attacks, like, for example, if someone were to type

"; a-MySQL query here;"

It would be executed, this would allow people access to compromise my system. I’m wondering how i could protect against things like this, possibly create a function that filters out the query looking for bad statements? or perhaps not allowing the ; character?

To sum it all up:

  • Whats the common practice now adays to prevent injection attacks?
  • How should I go about it?
  • How effective will this solution be against people who know what they are doing from changing my database.
  • 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-16T02:05:18+00:00Added an answer on May 16, 2026 at 2:05 am

    The only way is to properly escape user-submitted data. Others have pointed out some ways of doing so.

    There’s another way: prepared statements and placeholders. Prepared statements are supported by every modern PHP database interface, including mysqli and PDO.

    Let’s use PDO as a demonstration. Let’s say we wanted to update a bit of data in the table foo submitted by a user.

    $sql = 'UPDATE foo SET bar = ? WHERE user_id = ?';
    $sh = $db->prepare($sql);
    $sh->execute(array( $_POST['bar'], $_SESSION['user_id'] ));
    

    The variables in the array passed to execute replace the question mark placeholders in the query. When this happens, they are automatically escaped and quoted. You don’t need to manually escape them to make them safe to put in the database!

    On the other hand, you will still need to filter them for unexpected content, like HTML, Javascript, letters where you expect numbers, etc. Making data safe to insert into the database is only half of the battle.

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

Sidebar

Related Questions

Hey there, i want to store some session info from a database query, upon
Hey there! now first of all some might want to shout that there are
hey there, i have a div that expands when the page is loaded, now
Hey there. I'm trying to write a small program that will read the four
Hey there, was wondering if anyone could help a newbie on SQL and Python.
Hey there you lot, is there a way that I can open a lightbox
Hey there. I have a c# application that parses txt files and imports the
hey there i have this code that should save a file from sql server
hey there guys and girls i have this code that saves json as a
hey there i am having problem i have List<List<memoryCard>> that i want to show

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.