I'm trying to declare variables and arrays from a form (post) but it seems the arrays are not being processed:
// is this a better practise than directly pass the entire $_POST?
$list = array('use', 'type', 'status', 'bhk', 'baths', 'size', 'location', 'price', 'description');
foreach($list as $name) {
if ($name != 'description')
$var = "\$" . $name . "=filter_input(INPUT_POST, '" . $name . "', FILTER_SANITIZE_NUMBER_INT);";
else if ($name == 'description')
$var = "\$" . $name . "=filter_input(INPUT_POST, '" . $name . "', FILTER_SANITIZE_STRING);";
}
$area_1 = $size['area1'] != '' ? $size['area1'] : 0;
$area_2 = $size['area2'] != '' ? $size['area2'] : 0;
$city = $location['city'];
$zone = $location['zone'];
$sale = $price['sale'] != '' ? $price['sale'] : 0;
$rent = $price['rent'] != '' ? $price['rent'] : 0;
Could be that some of those inputs are long numbers? Like $price['sale']
(up to 999999) or $size['area1']
(up to 999). Since they don't need any unit type I prefer storing them as integers rather than strings. But tell me if the length is a problem.
EDIT: (FIX by @swidmann in comments)
$$name = filter_input(INPUT_POST, $name, FILTER_SANITIZE_NUMBER_INT);
Solution: (by @swidmann in comments)
$$name = filter_input(INPUT_POST, $name, FILTER_DEFAULT , FILTER_REQUIRE_ARRAY)