我正在尝试为搜索员工编写代码,我收到错误“Undefined index: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>
答案 0 :(得分:0)
<?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);
?>