PHP Database Handling Program

<html>
<body><title>PHP Program</title>
<form name=frminfo method=post>
Enter Roll no.<input type=text name=r1>
                    <input type=submit>
</form>
</body>
</html>


MySQL Table Design :

create database College;

use College;

 Create Table student
   (
    rno numeric(4) Primary key,
    name varchar(20) Not null,
    adres varchar(10)
   );


 insert into student values(1,'Amol K','Pune');
 insert into student values(2,'Biju C','Rajkot');
 insert into student values(3,'Chetan D','Gwalior');

 --------- 



<?php
echo "<h3>Accept roll no. of student and display student information from MySQL database.</h3> ";


if(isset($_POST['r1']))
  {
   $rollno=$_POST['r1'];
   $cn=mysql_connect("localhost","root");  
       mysql_select_db("College",$cn);
   $query="Select * from student where rno=" .$rollno;
   $res=mysql_query($query);
   
    if(mysql_num_rows($res)>0)
      {
      $row=mysql_fetch_row($res);
      echo "<table border=1><tr><td>R.No</td><td>Name</td><td>Address</td></tr>";
      echo "<tr><td>  $row[0]</td><td> $row[1]</td><td>$row[2] </td></tr></table>";
      }
else
     echo "<h3> Record Not Found</h3>";


  }
?>

No comments:

Post a Comment

Thanks for visiting my Blog!

Have a Question ? Need Help in College Assignments, Need Code that is not available here? Just leave a comment & get your code instantly.

Tips to Enhance Your Blog