Tuesday, 2 July 2013

Edit,update & delete Coding in the database using PHP



On click the edit option in the page , it will be go to edit.php page  and by using  id value in the database the values will be fetched from database.

edit.php:

<?php
$s=$_GET['edit'];
if(isset($_GET['edit']))
{
    $varname=mysql_query("select * from tablename where id='$s'",$conn);
    while($row=mysql_fetch_array($varname))
    {
       $varname1=$row['databasename'];
       echo '$varname1';
    }
}
?>



After by editing the values we have to update the form. For that we will have the following coding.


Update code:


$s=$_GET['edit'];
if(isset($_POST['update'])

{
    $varname=$_POST['fieldname'];
    $update=mysql_query("update tablename set databasename='$varname'where id='$s'");
    if($update)
    {
        echo"<script>alert('updated')</script>";
}
}


On click the delete option in the page , it will automatically delete by using  id value in the database and return to the view page.

delete code:

<?php
s=$_GET['delete'];
if(isset($_GET['delete']))
{
    $delete=mysql_query("delete from upload where id='$s'")or die(mysql_error());
    }
?>