0

I have a little problem here. Can you help me with this error?

"Notice: Undefined index:"

My code:

<?php
  $a1 = $_GET['scitovanie_1'];    //error 
  $a2 = $_GET['scitovanie_2'];    //error
  $b1 = $_GET['odcitovanie_1'];   //error
  $b2 = $_GET['odcitovanie_2'];   //error
  $c1 = $_GET['nasobenie_1'];     //error
  $c2 = $_GET['nasobenie_2'];     //error
  $d1 = $_GET['delenie_1'];       //error
  $d2 = $_GET['delenie_2'];       //error

  if($a1 AND $a2){
    $vysledok = $a1 + $a2;

    echo $vysledok;
  }else if($b1 AND $b2){
    $vysledok = $b1 - $b2;

    echo $vysledok;
  }else if($c1 AND $c2){
    $vysledok = $c1 * $c2;

    echo $vysledok;
  }else{
if($d1 AND $d2){
    $vysledok = $d1 / $d2;

    echo $vysledok;
  }
}
?>

Thank you for your response.

  • 7
    Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – B. Desai Oct 03 '17 at 10:59
  • use isset( $_GET[ index ]) at first to make sure you receive those parameters in $_GET – shashi Oct 03 '17 at 11:00
  • please show full error @Radoslav Rác – Pritamkumar Oct 03 '17 at 11:02

1 Answers1

2

check for all response variable if isset or not manually

$a1 = isset($_GET['scitovanie_1'])?$_GET['scitovanie_1']:""; 

for all variable so if not set than set value blank

Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
  • It is working thank you. Can you explain me why i must add ?$_GET['scitovanie_1']:"" ? – Radoslav Rác Oct 03 '17 at 11:12
  • because it is for checking that variable exists or not some variable which we get from the may be set or some may be not so for checking the presence of variable we can use this,for more info you can check following link:-http://php.net/manual/en/function.isset.php – nikita Oct 03 '17 at 11:14
  • bcoz if value (?) than set to variable else(:) assign "" empty string to varibale – Bhargav Chudasama Oct 03 '17 at 11:14