How to Delete the Record in PHP GUI Application

Program 1

<html>
<body>
    <center>
    <form method=post action="StudentDelete.php">
      <table border=1>  
        <tr>
            <th>Student Id For Delete</th>
            <td><input type=text name=txtid></td>
        </tr>
        <tr>
        <td></td>
        <td><input type=submit value=Search name=btnSubmit></td>
        </tr>
</table> 
</form>
<pre>
<?php

     if(isset($_POST['btnSubmit']))
     {
           
        $stid=$_POST['txtid'];
        session_start();
        $_SESSION['studid']=$stid;
        $mycon=mysqli_connect("localhost","root","","Library") or die("Connection not success");
        //echo "Connection sucees<br>"; 
        $sql="select * from studentdata where sid=".$stid;
        $record=$mycon->query($sql);
        if(mysqli_num_rows($record)>0)
        {
         ?>         
            <table border=1>
                <tr>
                    <th>Roll No</th><th>Name</th><th>Phy</th><th>Chem</th><th>Maths</th>
               </tr>
               <tr>
          <?php
            while($row=mysqli_fetch_assoc($record))
             {
                   echo "<td>". $row['sid']."</td>";
                   echo "<td>". $row['sname']."</td>";
                   echo "<td>". $row['phy']."</td>";
                   echo "<td>". $row['chem']."</td>";
                   echo "<td>". $row['math']."</td>";
                   echo "<form method=post action=DeleteData.php>";
                   echo "<td><input type=submit value=Delete></td>";
                   echo "</form>";
            }
      }       
        else
        echo "<font color=red size=5>Record not found</font>";
     
}   
?>
</tr>
</pre>
</center>
</body>
</html>

Program 2

<html>
<body>
    <center>
    <form method=post action="StudentDelete.php">
      <table border=1>  
        <tr>
            <th>Student Id For Delete</th>
            <td><input type=text name=txtid></td>
        </tr>
        <tr>
        <td></td>
        <td><input type=submit value=Search name=btnSubmit></td>
        </tr>
</table> 
</form>
<pre>
<?php

     if(isset($_POST['btnSubmit']))
     {
           
        $stid=$_POST['txtid'];
        session_start();
        $_SESSION['studid']=$stid;
        $mycon=mysqli_connect("localhost","root","","Library") or die("Connection not success");
        //echo "Connection sucees<br>"; 
        $sql="select * from studentdata where sid=".$stid;
        $record=$mycon->query($sql);
        if(mysqli_num_rows($record)>0)
        {
         ?>         
            <table border=1>
                <tr>
                    <th>Roll No</th><th>Name</th><th>Phy</th><th>Chem</th><th>Maths</th>
               </tr>
               <tr>
          <?php
            while($row=mysqli_fetch_assoc($record))
             {
                   echo "<td>". $row['sid']."</td>";
                   echo "<td>". $row['sname']."</td>";
                   echo "<td>". $row['phy']."</td>";
                   echo "<td>". $row['chem']."</td>";
                   echo "<td>". $row['math']."</td>";
                   echo "<form method=post action=DeleteData.php>";
                   echo "<td><input type=submit value=Delete></td>";
                   echo "</form>";
            }
      }       
        else
        echo "<font color=red size=5>Record not found</font>";
     
}   
?>
</tr>
</pre>
</center>
</body>
</html>

 

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *