未定义的索引:DLL

时间:2011-11-01 11:36:40

标签: php html

<?php

if (isset($_POST['first']) && isset($_POST['second']) && isset($_POST['submit']) && $_POST['DDL'] == "+")
{
    $equals = $_POST['first'] + $_POST['second'];
}
if (isset($_POST['first']) && isset($_POST['second']) && isset($_POST['submit']) && $_POST['DDL'] == "-")
{
    $equals = $_POST['first'] - $_POST['second'];
}
if (isset($_POST['first']) && isset($_POST['second']) && isset($_POST['submit']) && $_POST['DDL'] == "*")
{
    $equals = $_POST['first'] * $_POST['second'];
}
if (isset($_POST['first']) && isset($_POST['second']) && isset($_POST['submit']) && $_POST['DDL'] == "/")
{
    $equals = $_POST['first'] / $_POST['second'];
}

print $_POST['DDL']; // THIS IS THE LINE THAT RESULTS IN THE ERROR! WHY?

?>

<html>
<body>

<form method="post">

<input type="text" name="first">

<select name="DDL">
<option value="+" selected="selected">+</option>
<option value="-">-</option>b
<option value="*">*</option>
<option value="/">/</option>
</select>

<input type="text" name="second">
<input type="submit" name="submit" value="Equals">
<input type="text" name="equals" value="<?php if (!empty($equals)) print($equals) ?>">

</form>

</body>
</html>

在提交表单之前访问index.php文件时,前面的代码会导致以下错误:

a busy cat http://i42.tinypic.com/11jaf5x.png

php代码“print $ _POST ['DDL'];”导致错误。

为什么会这样? 我已经使用“+”...

选择了默认值

1 个答案:

答案 0 :(得分:1)

首次访问该页面时,您没有任何发布数据。 这会引发您遇到的异常。

在处理表单数据之前,你应该检查$ _POST值/存在。

希望这会有所帮助:-)