Undefined index: btn_save…error in php [closed]-Collection of common programming errors

You might have something like this in your script:

$btn_save = $_GET['btn_save'];

or

$btn_save = $_POST['btn_save'];

You might replace it with:

$btn_save = (isset($_GET['btn_save']) ? $_GET['btn_save'] : null);

or

$btn_save = (isset($_POST['btn_save']) ? $_POST['btn_save'] : null);

accordingly

At first time you run your script without ?btn_save=[something] and $_GET has no key like btn_save.

However, it would be better to design a validator which will return error messages in cases like:

  • Required field is empty
  • The field should be numeric
  • The field should be alpha-numeric
  • etc

Originally posted 2013-11-10 00:14:50.