- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Search Employee</title>
- </head>
- <body>
- <h2>Search Employee</h2>
- <form method="post">
- Enter Employee Number: <input type="text" name="empno">
- <input type="submit" value="Search">
- </form>
- <?php
- // Check if form is submitted
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- // Retrieve entered EmpNo
- $empno = $_POST['empno'];
- // Database credentials
- $servername = "localhost";
- $username = "your_username";
- $password = "your_password";
- $dbname = "employee_db";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Prepare SQL query
- $sql = "SELECT * FROM employees WHERE EmpNo = ?";
- $stmt = $conn->prepare($sql);
- $stmt->bind_param("i", $empno);
- $stmt->execute();
- $result = $stmt->get_result();
- // Display results in a table
- if ($result->num_rows > 0) {
- echo "<h3>Employee Details</h3>";
- echo "<table border='1'>";
- echo "<tr><th>EmpNo</th><th>EmpName</th><th>Designation</th><th>DOJ</th><th>BasicPay</th><th>DA</th></tr>";
- while ($row = $result->fetch_assoc()) {
- echo "<tr>";
- echo "<td>" . $row['EmpNo'] . "</td>";
- echo "<td>" . $row['EmpName'] . "</td>";
- echo "<td>" . $row['Designation'] . "</td>";
- echo "<td>" . $row['DOJ'] . "</td>";
- echo "<td>" . $row['BasicPay'] . "</td>";
- echo "<td>" . $row['DA'] . "</td>";
- echo "</tr>";
- }
- echo "</table>";
- } else {
- echo "<p>No employee found with EmpNo: $empno</p>";
- }
- // Close statement and connection
- $stmt->close();
- $conn->close();
- }
- ?>
- </body>
- </html>