php - Is it safe to let the user specify the mysql field to search? -
i have search program has multiple input text boxes correspond fields in mysql database. know if safe have custom search box user can enter actual field searched , value.
like this:
<form method='post'> <input type='text' name='param1' /> <input type='text' name='param2' /> <input type='text' name='customfield' /> <input type='text' name='customvalue' /> </form>
then when submitted:
$param1 = mysql_real_escape_string($_post['param1']); $param2 = mysql_real_escape_string($_post['param2']); $customfield = mysql_real_escape_string($_post['customfield']); $customvalue = mysql_real_escape_string($_post['customvalue']); $query = "select * mytable field1 '" . $param1 . "' , field2 '" . $param2 . "' , " . $customfield . " '" . $customvalue . "'";
this internal webpage , few of see these new boxes know if sql injection possible here.
you should check fields provided in list/array of fields allow searching within. add backticks around field names in query safe well. doing both things prevent injection through variables.
Comments
Post a Comment