In this tutorial, we will learn the followings;
- PHP program to show the student information.
- PHP program to show the student information with form values entered by the user.
- PHP program to show the student information with a database
Step 1 :
<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;
?>
Step 2 :
<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>";
}
?>
Step 3 :
<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>
No comments:
Post a Comment