Can someone tell me if this code is open to SQL Injection and why:
$x = $_REQUEST['id'];
$x = mysql_real_escape_string($x);
$del = "DELETE FROM Y WHERE id = ".$x;
mysql_query($del);
Can someone tell me if this code is open to SQL Injection and why:
$x = $_REQUEST['id'];
$x = mysql_real_escape_string($x);
$del = "DELETE FROM Y WHERE id = ".$x;
mysql_query($del);
 
    
     
    
    It is; consider x being id, which leads to a query of
DELETE FROM Y WHERE id = id
deleting all the rows from the table.
 
    
    It is because you dont quote the x.
You can also use something simple like:
sprintf("DELETE FROM Y WHERE id = %u", $x);
 
    
    It shouldn't be as you use mysql_real_escape_string() to escape it
