I am looking for a secure php / sql statement to filter a database between a min and max number i want to make sure and doesn't deliver errors if a person does or does not use a decimal and if they enter a higher number for min thanks!
http://www.php.net/is_numeric will check the inputs are numeric for you. If you don't do, echo mysql_error(); in your code, the user would never see the SQL errors (if any). Jay
Something like ... $min = 123.45; $max = 567.89; $min = mysql_real_escape_string($min); $max = mysql_real_escape_string($max); $query = "SELECT * FROM `table` WHERE `min` > $min AND `max` < $max"; $result = mysql_query($query); // ... Continue processing here ... PHP: Jay
$min = 123.45; $max = 567.89; if(is_numeric($min) && is_numeric($max)) { $query = "SELECT * FROM `table` WHERE `min` > $min AND `max` < $max"; $result = mysql_query($query); // ... Continue processing here ... }else{ //ERROR CODE TO GO HERE } PHP: NOTE: If you use is_numeric() on the two values you will not need to escape the data with mysql_real_escape_string()