Any reason why PHP is throwing a warning 'undefined index' when post data is set as -1?
print_r($_POST);
// returns
Array ( [id] => -1 [colour] => red )
// warning occurs on following line
if($_POST['id'] != 0){
// ...
}
Any reason why PHP is throwing a warning 'undefined index' when post data is set as -1?
print_r($_POST);
// returns
Array ( [id] => -1 [colour] => red )
// warning occurs on following line
if($_POST['id'] != 0){
// ...
}
Your code works flawlessly:
<?php
$_POST = array(
'id' => '-1',
'colour' => 'red',
);
print_r($_POST); // returns Array ( [id] => -1 [colour] => red )
// No warning occurs on following line
if($_POST['id'] != 0){
// ...
}
The error is somewhere else.