The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Emo details
By Guest on 26th July 2024 07:29:57 AM | Syntax: PHP | Views: 33



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Employee Search</title>
  5.     <style>
  6.         table {
  7.             width: 100%;
  8.             border-collapse: collapse;
  9.         }
  10.         th, td {
  11.             border: 1px solid black;
  12.             padding: 8px;
  13.             text-align: left;
  14.         }
  15.         th {
  16.             background-color: #f2f2f2;
  17.         }
  18.     </style>
  19. </head>
  20. <body>
  21.     <h2>Employee Search</h2>
  22.     <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  23.         <label for="emp_no">Enter Employee Number:</label>
  24.         <input type="text" id="emp_no" name="emp_no">
  25.         <input type="submit" value="Search">
  26.     </form>
  27.    
  28.     <?php
  29.     // Check if form is submitted
  30.     if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET['emp_no'])) {
  31.         $emp_no = $_GET['emp_no'];
  32.        
  33.         // Connect to MySQL database
  34.         $servername = "localhost";
  35.         $username = "your_username";
  36.         $password = "your_password";
  37.         $dbname = "your_database_name";
  38.        
  39.         $conn = new mysqli($servername, $username, $password, $dbname);
  40.        
  41.         // Check connection
  42.         if ($conn->connect_error) {
  43.             die("Connection failed: " . $conn->connect_error);
  44.         }
  45.        
  46.         // Prepare SQL query
  47.         $sql = "SELECT * FROM employees WHERE emp_no = ?";
  48.         $stmt = $conn->prepare($sql);
  49.         $stmt->bind_param("i", $emp_no);
  50.        
  51.         // Execute query
  52.         $stmt->execute();
  53.         $result = $stmt->get_result();
  54.        
  55.         // Display results in a table
  56.         if ($result->num_rows > 0) {
  57.             echo "<h3>Search Results:</h3>";
  58.             echo "<table>";
  59.             echo "<tr><th>Employee Number</th><th>Employee Name</th><th>Designation</th><th>Date of Birth</th><th>Basic Pay</th><th>DA</th></tr>";
  60.            
  61.             while ($row = $result->fetch_assoc()) {
  62.                 echo "<tr>";
  63.                 echo "<td>" . $row['emp_no'] . "</td>";
  64.                 echo "<td>" . $row['emp_name'] . "</td>";
  65.                 echo "<td>" . $row['designation'] . "</td>";
  66.                 echo "<td>" . $row['dob'] . "</td>";
  67.                 echo "<td>" . $row['basic_pay'] . "</td>";
  68.                 echo "<td>" . $row['da'] . "</td>";
  69.                 echo "</tr>";
  70.             }
  71.            
  72.             echo "</table>";
  73.         } else {
  74.             echo "<p>No employee found with Employee Number: $emp_no</p>";
  75.         }
  76.        
  77.         // Close statement and database connection
  78.         $stmt->close();
  79.         $conn->close();
  80.     }
  81.     ?>
  82. </body>
  83. </html>





emo details