<?php
echo '
<form action="index.php" method="post">
<input name="n1"><br>
<input name="n2"><br>
<input type="submit" name="js" value="加">
<input type="submit" name="js" value="减">
<input type="submit" name="js" value="乘">
<input type="submit" name="js" value="除">
</form>';
$n1 = $_POST['n1'];
$n2 = $_POST['n2'];
$js = $_POST['js'];
if ($js=='加')
$jg=$n1+$n2;
if ($js=='减')
$jg=$n1-$n2;
if ($js=='乘')
$jg=$n1*$n2;
if ($js=='除' and $n2!=0)
$jg=$n1/$n2;
if ($js=='除' and $n2==0)
$jg='除数不能为0!';
echo '结果:'.$jg;
?>
为什么不发送任何数据就会 Notice: Undefined index: n1 in /data/data/android.wwwroot/index.php on line 11
Notice: Undefined index: n2 in /data/data/android.wwwroot/index.php on line 12
Notice: Undefined index: js in /data/data/android.wwwroot/index.php on line 13
Notice: Undefined variable: jg in /data/data/android.wwwroot/index.php on line 24
1.赋予默认值:
$n1 = isset($_POST['n1'])?$_POST['n1']:1;
2.@屏蔽错误信息:
$n1 = @$_POST['n1'];
相对1L的屏蔽所有错误信息更利于排错
error_reporting(E_ERROR | E_WARNING | E_PARSE);
在你的代码前加上上面的,就可以了。