Advertisement
Hydrase

Search for a record in Student1

Mar 4th, 2025
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Student Records</title>
  6. </head>
  7. <body>
  8.  
  9. <h2>Search Student Record</h2>
  10. <form method="POST">
  11. Enter Roll Number: <input type="text" name="rollno" required>
  12. <input type="submit" name="search" value="Search">
  13. </form>
  14.  
  15. <?php
  16. if (isset($_POST['search'])) {
  17. $rollno = $_POST['rollno']; // Get roll number from user input
  18.  
  19. // Database connection
  20. $conn = mysqli_connect("localhost", "root", "", "COLLEGE");
  21.  
  22. if ($conn->connect_error) {
  23. die("Connection Failed: " . $conn->connect_error);
  24. }
  25.  
  26. echo "Connected successfully<br>";
  27.  
  28. // Prepare SQL query to search for the given Roll Number
  29. $sql = "SELECT SID, NAME, EMAIL, FEES, DOB FROM STUDENT WHERE SID = ?";
  30. $stmt = $conn->prepare($sql);
  31. $stmt->bind_param("s", $rollno);
  32. $stmt->execute();
  33. $result = $stmt->get_result();
  34.  
  35. // Check if record exists
  36. if ($result->num_rows > 0) {
  37. echo "<h3>Record Found:</h3>";
  38. echo "<table border='1'>
  39. <tr>
  40. <th>ID</th>
  41. <th>NAME</th>
  42. <th>EMAIL</th>
  43. <th>FEES</th>
  44. <th>DOB</th>
  45. </tr>";
  46.  
  47. while ($row = $result->fetch_assoc()) {
  48. echo "<tr>
  49. <td>" . $row["SID"] . "</td>
  50. <td>" . $row["NAME"] . "</td>
  51. <td>" . $row["EMAIL"] . "</td>
  52. <td>" . $row["FEES"] . "</td>
  53. <td>" . $row["DOB"] . "</td>
  54. </tr>";
  55. }
  56. echo "</table>";
  57. } else {
  58. echo "<h3>No record found for Roll Number: $rollno</h3>";
  59. }
  60.  
  61. // Close connections
  62. $stmt->close();
  63. $conn->close();
  64. }
  65. ?>
  66.  
  67. </body>
  68. </html>
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement