PHP program to show student info name and roll number with mysql

PHP program to show student info name and roll number with MySql



php program to show student info name and roll number with mysql



In this tutorial, we will learn how to show student information names and roll numbers using the PHP program. 

Follow to create empty file and database:

1. create a database and name it Students and create student_table

2. Two PHP Empty files to create like:
 
     1. studentreg.php - for registration of student roll no and student name.

     2. showdetails.php - This page is for retrieve or fetch student data and show the details of the student.

Create Database:



create table student_table (roll_no int(11) not null primary key unique,
student_name varchar(50) not null);

1. Studentreg.php




  
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h2 style="text-align:center;margin-top:50px;">dailyaspirants.com</h2>
<br/>
<br/>
<br/>
<h1>Enter for Student Name and Roll NO</h1>
<form  method="post">
<div class="mb-3">
  <label for="exampleFormControlInput1" class="form-label">Name</label>
  <input type="text" name="name" class="form-control" id="exampleFormControlInput1" placeholder="Name">
</div>
<div class="mb-3">
  <label for="exampleFormControlTextarea1" class="form-label">Roll Number</label>
  <input type="text" name="rno" class="form-control" id="exampleFormControlInput1" placeholder="Roll Number">
</div>
<input class="btn btn-primary" type="submit" name="submit" />
</form>
</div>
<!--- php code--->
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
</body>
</html>
  
  



  
<?php  
$con=mysqli_connect("localhost","root","","students");
if(isset($_POST['submit'])){
$student_name =$_POST['name'];
$roll_no =$_POST['rno'];   
//$sql=mysqli_query($con,"INSERT INTO student_table (roll_no,student_name) VALUES ('$roll_no','$student_name')");
$sql="INSERT INTO student_table (roll_no,student_name) VALUES ('$roll_no','$student_name')";
if($con->query($sql)===True)
{
	echo "insert successfully";
}
else{
	echo "error in upload file";
}
}

$con->close();

?>
  
  



php program show student information


Register Database Image:
php program show student information


2. Showdetails.php





<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h2 style="text-align:center;margin-top:50px;">dailyaspirants.com</h2>
<br/>
<br/>
<br/>
<h3>SHOW DETAILS USING STUDENT ROLL NO</h3>
<p>show output student name and roll number</p>
<form method="get">
<p>Enter Roll number</p>
<input type="text" name="number" />
<input type="submit" name="submit" />

<div class="card">
  <div class="card-body">
<!---php code--->
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
</body>
</html>




  
<?php

if(isset($_GET['submit'])){
$number = $_GET['number'];
$conn=mysqli_connect("localhost","root","","students");
   
   if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }
   
   $sql = "SELECT * FROM student_table where roll_no = '$number' ";
   $result = mysqli_query(  $conn,$sql );
   
   if(! $result ) {
      die('Could not get data: ' . mysqli_error());
   }
   
   while($row = mysqli_fetch_array($result)) {
      echo "roll_no :{$row[0]}  <br> ".
         "Student NAME : {$row[1]} <br> ".

         "--------------------------------<br>";
   }
   
   echo "Fetched data successfully\n";
   
   mysqli_close($conn);
}

?>
  
  

php program show student information


Result Image:
php program show student information














I hope you will learn something How to PHP program to show student info name and roll number with MySQL . And just copy and paste and edit whatever you want to change the code. Thank you...!
Previous Post Next Post