How to Update Record in PHP GUI Application

Program 1

<?php  include 'FrontPage.php'?>
<html>
<body>
    <br><br><br><br><br><br><br><br><br><br>
    <center>
    <form method=post action="StudentUpdate.php">
      <table border=1>  
        <tr>
            <th>Student Id For Update</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'];
     $mycon=mysqli_connect("localhost","root","","Library") or die("Connection not success");
     $sql="select * from studentdata where sid=".$stid;
        $record=$mycon->query($sql);
        if(mysqli_num_rows($record)>0)
        {
            session_start();
            $_SESSION['studid']=$stid;
         ?>         
            <table border=1>
                <tr>
                    <th>Roll No</th><th>Name</th><th>Phy</th><th>Chem</th><th>Maths</th>
               </tr>
               <tr>
          <?php
          echo "<form method=post action=UpdateData.php>";

            while($row=mysqli_fetch_assoc($record))
             {
                   echo "<td>". $row['sid']."</td>";
                  echo "<td><input type=text name=txtname value=".$row['sname']."></td>";
                  echo "<td><input type=text name=txtphy value=".$row['phy']."></td>"; 
                  echo "<td><input type=text name=txtchem value=".$row['chem']."></td>";  
                  echo "<td><input type=text name=txtmath value=".$row['math']."></td>";   
                   echo "<td><input type=submit value=Update></td>";
            }
            echo "</form>"; 
      }       
        else
        echo "<font color=red size=5>Record not found</font>";
}   
?>
</tr>
</pre>
</center>
</body>
</html

Program 2

<html>
<body>
    <center>
<pre>
  
<?php
  session_start();
  $id=$_SESSION['studid'];
  $name=$_POST['txtname'];
  $phy=$_POST['txtphy'];
  $chem=$_POST['txtchem'];
  $math=$_POST['txtmath'];
  //echo $id." ".$name." ".$phy." ".$chem." ".$math;
  $mycon=mysqli_connect("localhost","root","","Library") or die("Connection not success");
  $sql="update studentdata set sname=?,phy=?,chem=?,math=? where sid=?";
   $ps=$mycon->prepare($sql);
   $ps->bind_param("siiii", $name,$phy,$chem,$math,$id);
   $ps->execute();
    echo " Record update....";
    $ps->close();
    $mycon->close();
    session_unset();
    session_destroy();
?>
</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 *