获取错误“未定义的索引:employee_no”


Getting the error Undefined index: employee_no

我正在尝试为搜索员工编写代码,但收到错误"未定义的索引:employee_no"。

任何帮助将不胜感激。抱歉,如果这个问题没有正确发布。这是我第一次使用这个网站。

<head>
    <title>Search Employee</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" type="text/css" href="employee_form.css">
</head>
<body>
    <a href="index.html">Home</a>
    <?php
        require ('mysqli_connect.php');
        $employee_no = $_POST['emp_no']; //here is where it is saying the problem is
        $sql = mysqli_query($dbc, "SELECT * FROM employee WHERE emp_no='$employee_no'");
        while ($row = mysqli_fetch_array($sql)){
            $forename = $row['first_name'];
            $surname = $row['last_name'];
            $emp_no = $row['emp_no'];
            echo "<h2> Employee: ".$emp_no." ---> ".$forename." ".$surname."</h2>";
        }
        mysqli_close($dbc); 
    ?>
</body>
</html>

形式是

员工管理系统

    <h3>Search Employee: Enter the employee no!</h3>
    <form action="search_emp.php" method="POST">
        <p> Employee No: <input type="NUMBER" name="employee_no" min="101" max="999" required/> </p>
        <p> <button class="search_employee" type="submit">Search</button> </p>
    </form>

<?php
        require ('mysqli_connect.php');
        if(isset($_POST['emp_no']){
           $employee_no = $_POST['emp_no']; 
        }
        $sql = mysqli_query($dbc, "SELECT * FROM employee WHERE emp_no='$employee_no'");
        while ($row = mysqli_fetch_array($sql)){
            $forename = $row['first_name'];
            $surname = $row['last_name'];
            $emp_no = $row['emp_no'];
            echo "<h2> Employee: ".$emp_no." ---> ".$forename." ".$surname."</h2>";
        }
        mysqli_close($dbc);
    ?>