How can I prevent SQL injection in PHP?

How can I prevent SQL injection in PHP?

If user input is inserted without modification into an SQL query, then the application becomes vulnerable to&nbsp;<a href="https://stackoverflow.com/a/332367/" target="_blank">SQL injection</a>, like in the following example:

If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example:

$unsafe_variable = $_POST['user_input']; 

mysql_query("INSERT INTO table (column) VALUES ('$unsafe_variable')");

That's because the user can input something like value'); DROP TABLE table;--, and the query becomes:

INSERT INTO table (column) VALUES('value'); DROP TABLE table;--')

What can be done to prevent this from happening?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

CakePHP Development Company | Hire CakePHP Developers | Skenix

Skenix Infotech is a top CakePHP Website Development Company that offers feature-rich CakePHP Development Services. Hire expert CakePHP Developers from Skenix.

CakePHP Development Company | Skenix Infotech

Skenix Infotech is one of the most committed, expert and affordable **[CakePHP Development Company](https://www.skenix.com/cakephp-website-development/ "CakePHP Development Company")** in India and USA providing a broad range of CakePHP Services....

MySQL Tutorial - Learn MySQL from Scratch

Complete MySQL Course: Beginner to Advanced. MySQL Tutorial - Learn MySQL from scratch and go from beginner to advanced in MySQL.