0

//deleteimage.php file

<form action="dbdeleteimg.php" method="POST" enctype="multipart/form-data">
<select name="sub">
<?php
   $con=mysqli_connect("localhost","root","","rwtp");
   $sql="select * from image ";
   $result=mysqli_query($con,$sql);
   while($row=mysqli_fetch_array($result)){
       $name=$row[0];
    ?>
   <option value="<?php echo $name;?>" name="<?php echo $name; ?>" ><?php echo $name;?>
   </option>
    <?php
 }
 ?>
 </select>
 <input type="submit"/>
 </form>

The above file is the code to take code from the database and display it, upon selection of the particular option that value should be sent to the other file that is " dbdeleteimg.php "

//dbdeleteimg.php

<?php
   $con =mysqli_connect("localhost","root","","rwtp");
   if(!$con){
      die("connection error");
   }
   $name=$sub=$type="";
   if ($_SERVER["REQUEST_METHOD"] == "POST") {
       $name = $_POST["name"];
       $type=$_POST["sub"];
   }
   $sql="select * from image where name='$name'";
   $result=mysqli_query($con,$sql);
   $row=mysqli_fetch_array($result);
   $uploa=$row[3].$row[2];
   unlink($uploa);
   $sql="delete from image where name='$name'";
   if(mysqli_query($con,$sql)){     
    //header('Location: option.php');
    }else{
        echo "error";
    }
?>

enter image description here Now the above code is used to delete the image from the server and database. But after executing those files I'm getting an error

undefined index :name as shown in the image

Notice: Undefined index: name in C:\xampp\htdocs\RWTP\dbdeleteimg.php on line 8

Warning: unlink(): Invalid argument in C:\xampp\htdocs\RWTP\dbdeleteimg.php on line 15

enter image description here

0 Answers0