SQL injection is more vulnerable in web applications.
When using PHP with MySQL avoiding SQL injection is very simple.
The below code is not safe. Because once can inject own sql command here. like " 1; delete from customer where customerid = '1' ;" will delete the customer from table.
$customerId = $_GET["cid"];
$sql = "select * from customer where customerid = $customerId";
There is built-in function to prevent SQL Injection from MySQL library. Before passing the parameter to SQL, make the parameter as safe by calling this function like below.
$customerId = mysql_escape_string($customerId);
$sql = "select * from cutomer where cutomerid = $customerId";
Comments
Post a Comment