Site Owners Forums - Webmaster Forums

Site Owners Forums - Webmaster Forums (http://siteownersforums.com/index.php)
-   PHP / mySQL (http://siteownersforums.com/forumdisplay.php?f=10)
-   -   How to prevent SQL injection in PHP? (http://siteownersforums.com/showthread.php?t=64756)

Jack Hard 05-06-2013 04:46 AM

How to prevent SQL injection in PHP?
 
If user input is inserted into an SQL query directly, 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;--, making the query:

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

What should one do to prevent this?


All times are GMT -7. The time now is 11:54 AM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.