未定义的索引(2)

时间:2017-10-03 10:59:04

标签: php

我这里有点问题。 你能帮我解决这个错误吗?

"注意:未定义的索引:"

我的代码:

<?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;
  }
}
?>

感谢您的回复。

1 个答案:

答案 0 :(得分:2)

手动检查所有response变量issetnot

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

表示所有变量,如果未设置,则设置为空白