Friday, 4 September 2015

Delete the record in emp table

To delete the record in the emp table, we will need to create the design form so that user can input the value of his/her choice to delete the record....
delemp.html

<html>   
    <head>
    </head>
    <body>
        <form action=delemp.php method=POST>
        Enter no<input type=text name=n>
        <input type=submit value=DELETE>
        </form>
    </body>
</html>

To check if the record exists or not, we will need to write the code in PHP file...If the record is found, then that record will be deleted...If not found, then we will need to display appropriate message as follows:

delemp.php

<?php
    $no=$_POST['n'];
    $cn=mysql_connect("localhost","root") or die(mysql_error());
    $db=mysql_select_db("student",$cn) or die(mysql_error());
    $row=mysql_query("select * from emp where id=$no",$cn) or die(mysql_error());
    $n=mysql_num_rows($row);
    if($n<=0)
    {
        echo "Record not found";
        exit;
    }
    else
    {
        $q=mysql_query("delete from emp where id=$no");
        echo $q." Record Deleted";
       
    }
?>

No comments:

Post a Comment