1

// i have two tables like,projects and projectfiles.

projects fields are:

id,name,alice,catg,img;

//insertin the image in the folder 'upload'

projectfiles fields are :

id,name,img

//inserting the image in the folder 'image'

so,how delete the data from projects and projectfiles even from directory.

<?php 

    include('dbconfig1.php');


    if(!$db)
    {
        die(mysqli_error());
    }


    $sql = "select * from projects";
    $result = $db->query($sql);


    if(isset($_GET['id']))
    {
        $selectSql = "select * from projects where id = ".$_GET['id'];
        $rsSelect = mysqli_query($db,$selectSql);
        $getRow = mysqli_fetch_assoc($rsSelect);

        $getIamgeName = $getRow['img'];

        $createDeletePath = "upload/".$getIamgeName;

        if(unlink($createDeletePath))
        {
            $deleteSql = "delete from projects where id = ".$getRow['id'];
            $rsDelete = mysqli_query($db, $deleteSql);  

            if($rsDelete)
            {
                header('location:projects.php?success=true');
                exit();
            }
        }
        else
        {
            $errorMsg = "Unable to delete Image";
        }

    }


?>
        ?>

        <?php 
        if(isset($_GET['success']) && $_GET['success'] == 'true')
        {
        ?>
            <div class="alert alert-success">
                <?php 
                    echo "Images has been deleted sucessfully";
                ?>
            </div>
        <?php 
        }
        ?>
Strawberry
  • 33,750
  • 13
  • 40
  • 57

0 Answers0