Php Undefine Index Issue

时间:2012-11-01 15:24:00

标签: php

我正在使用php创建联系表单。但是当我在我的xampp服务器上运行它时,我收到一条错误消息。我不明白为什么会这样。我无法弄明白。以下是我的错误消息。

错误消息:

Notice: Undefined index: Send in D:\Software\Installed\xampp\htdocs\Omdatech-Co\eng\resellers.php on line 91 (First Line ex: if(isset($_POST['Send']) & $_POST['Send'] == "Submit")) 

Php代码:

<?php
        if(isset($_POST['Send']) & $_POST['Send'] == "Submit")
        {
            $fname = mysql_real_escape_string($_POST['fname']);
            $email = mysql_real_escape_string($_POST['email']);
            $conum = mysql_real_escape_string($_POST['conum']);
            $country = mysql_real_escape_string($_POST['country']);
            $find = mysql_real_escape_string($_POST['find']);
            $msg = mysql_real_escape_string($_POST['msg']);

            $err = array();

if(isset($fname) & isset($email) & isset($conum) & isset($country) & isset($find) & 
isset($msg))
            {
if(empty($fname) & empty($email) & empty($conum) & empty($country) & empty($find) & 
empty($msg))
                {
                    $err[] = "All field require";
                }
                else
                {
                    if(empty($fname))
                    $err[] = "Your first name require";
                }

            }
            else
            {
            if(!empty($err))
                            {
                                foreach($err as $er)
                                {
                                    echo "<font color=red>$er</font><br/>";
                                }
                            }
                            else
                            {
                                echo "Thank you.";
                            }
            }

        }           
        ?>

任何人都可以解决这个问题吗?为什么我收到这条消息?

1 个答案:

答案 0 :(得分:3)

因为在需要逻辑运算符时使用了按位运算符:

if(isset($_POST['Send']) && $_POST['Send'] == "Submit")

请注意两个&&而不是&

逻辑运算符短路,因此当isset()返回false时,不会评估以下比较。按位运算符尝试计算值,并评估比较,因此警告。