Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I saving myself from sql injections?

Am I doing this right? Will this help avoid sql injections?

$deleteid = htmlspecialchars(strip_tags(mysql_real_escape_string($_POST['listid'])));

mysql_send("DELETE FROM stage where listid='$deleteid'");
like image 845
user342391 Avatar asked Nov 29 '22 04:11

user342391


2 Answers

No.

You should call nothing but mysql_real_escape_string.

The htmlspecialchars and strip_tags functions are used to encode strings to be displayed as HTML.
They should not be used with SQL

like image 179
SLaks Avatar answered Dec 06 '22 05:12

SLaks


It may prevent SQL injection attacks, but its a poor way to approach it. Use prepared queries instead.

Since your comment says you're systematically making changes to your whole site, go with the better approach. While you're at it, you may want to move to a non-MySQL-specific database API, in case you want to switch to another backend later.

like image 32
Phil Miller Avatar answered Dec 06 '22 06:12

Phil Miller