forum

Home / DeveloperSection / Forums / How to prevent SQL injection in PHP?

How to prevent SQL injection in PHP?

Anonymous User255117-Apr-2013
Hi Everyone!

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?

Thanks in advance!

Updated on 17-Apr-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By