Say I have an array of key-value pairs with non-numerical keys. If I am going to be using those keys as values in an SQL INSERT statement, is it important to sanitize them as well?
Something like:
$food = array('fruit'=>'apple', 'veggie'=>'tomato', 'bread'=>'wheat');
foreach($food as $foodType => $nameOfFood)
{
$nameOfFood = stripslashes($nameOfFood);
$foodType = stripslashes($foodType); //Is this necessary?
$query = "INSERT INTO Foods(FoodType, NameOfFood) VALUES ($foodType, $nameOfFood)";
// Execute query
}
If the $food
array was populated through a POST statement, would sanitizing the keys be a concern?