Monday, 7 September 2015

Display the record in table format and allow all operations on that table

The following code will allow the user to display all the records in the table format. It will allow edit, delete and insert operation on a particular record. Note that there will be one line change in the code of udpate.php and delete.php file that has been displayed in this code.
disp.php

<?php
    $cn=mysql_connect("localhost","root") or die(mysql_error());
    $db=mysql_select_db("student",$cn) or die(mysql_error());
    $row=mysql_query("select * from stud",$cn) or die(mysql_error());
    $no=mysql_num_rows($row);
    echo "<h2> Student Details </h2>";
    echo "<table border=3>";
    echo "<tr><th>No<th>Name<th>City<th colspan=2><a href=stud.html>Add New Record</a>";
    for($i=1;$i<=$no;$i++)
    {
        $data=mysql_fetch_row($row);
        echo "<tr>";
        echo "<td>".$data[0];
        echo "<td>".$data[1];
        echo "<td>".$data[2];
        echo "<td> <a href=edit.php?id=".$data[0].">Modify</a>";
        echo "<td> <a href=delete.php?id=".$data[0].">Delete</a>";
    }
?>  

In edit.php file,
<?php
    $no=$_REQUEST['id'];
...........
...........
............

?>
in place of
<?php
     $no=$_POST['id'];
 ......
......
.....
?>
Remaining code is same .........

In delete.php file,
<?php
    $no=$_REQUEST['id'];
............
............
............
header("Location:disp.php");
?>
in place of
<?php
     $no=$_POST['id'];
.........
..........
.........
echo "Record deleted";
?>
Remaining code is same .........


2 comments: