PHP Program to show student info – name and roll number with Mysql
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
PHP program to show the student information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<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> |