0% found this document useful (0 votes)
1 views1 page

Search A Row in Database Using PHP

This document contains an HTML form for searching a student's registration number and a PHP script that connects to a MySQL database to retrieve student information based on the entered registration number. If a matching record is found, it displays the student's registration number, name, and age; otherwise, it shows '0 results'. The script handles database connection errors and processes form submissions using the POST method.

Uploaded by

bholdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

Search A Row in Database Using PHP

This document contains an HTML form for searching a student's registration number and a PHP script that connects to a MySQL database to retrieve student information based on the entered registration number. If a matching record is found, it displays the student's registration number, name, and age; otherwise, it shows '0 results'. The script handles database connection errors and processes form submissions using the POST method.

Uploaded by

bholdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1 <html>

2 <body>
3 <form action="" method="post">
4 Enter Reg No to be searched<input type="text" name="x"></br>
5 <input type="submit" value="Search"><input type="reset" value="clear">
6 </form>
7 </body></html>
8
9 <?php
10 $servername='localhost';
11 $username='root';
12 $password="";
13 $dbname='bsc';
14
15 $conn = mysqli_connect($servername, $username, $password,$dbname);
16
17 if (!$conn)
18 {
19 die("Connection failed:".mysqli_connect_error());
20 }
21 else if($_SERVER['REQUEST_METHOD']=="POST")
22 {
23 $regno=$_POST['x'];
24
25 $sql = "SELECT * FROM student WHERE regNo='$regno'";
26 $result = mysqli_query($conn, $sql);
27
28 if (mysqli_num_rows($result) > 0)
29 {
30 while($row = mysqli_fetch_assoc($result))
31 {
32 echo "Student Reg No:" . $row["regNo"]."</br>";
33 echo "Student name: " . $row["name"]."</br>";
34 echo "Student Age:" . $row["age"]."</br>";
35 echo "</br>";
36 }
37
38 }
39 else
40 {
41 echo "0 results";
42 }
43
44 }
45
46 ?>
47

You might also like