Site icon T4Tutorials.com

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 the followings;

  1. PHP program to show the student information.
  2. PHP program to show the student information with form values entered by the user.
  3. PHP program to show the student information with a database

PHP program to show the student information

<html>
<h2>T4Tutorials.com</h2>
<h3>simple programm</h3>
<p>show output student name and roll number</p>

</html>

<?php
class student
{
    public $name= 'ali';
	public $rno=55;
}
$a = new student();
echo $a->name;
echo "<br>";
echo $a->rno;
echo "<br>";
$b = new student ();
echo $b->name;
echo "<br>";
echo $b->rno;
?>

PHP program to show the student information with form values entered by the user

<html>
<h2>T4Tutorials.com</h2>
<h3>Form program</h3>
<p>show output student name and roll number</p>
</html>
<html>
<body>
<form method="post">
<p>Enter Name</p>
<input type="text" name="name" />
<p>Enter Roll number</p>
<input type="text" name="number" />
<input type="submit" name="submit" />
</form>
<?php
class student
{
    public $name= 'ali';
	public $rno=77;
}
$a = new student();
if(isset($_POST['submit'])){
$a->name=$_POST['name'];
$a->rno=$_POST['number'];
echo"Name of student= $a->name</h2><br>";
echo"Roll number of student= $a->rno</h2>";
}
?>
</body>
</html>

PHP program to show the student information with a database

<html>
<head>
<style>
div {
	align:center;
	width:400px;
	height:300px;
border: solid black;
background-color:orange;

padding: 20px;
}

</style>
</head>
<body>
<div>
<h1>Enter data for Student</h1>
<form  method="post">
Name:<br />
<input type="text" name="name"/><br />
Roll number:<br />
<input type="text" name="rno"/>
<br><br>
<input type="submit" name="OK" />
</form>
<?php  
$con=mysqli_connect("localhost","root","","student");
if(isset($_POST['OK'])){
$p =$_POST['name'];
$f =$_POST['rno'];   
$sql=mysqli_query($con,"INSERT INTO students (name,rno) VALUES ('$p','$f')");
}
?> 
</div>
</body>

</html>
Figure: PHP Program to show student info – name and roll number with MySQL
Exit mobile version