0
 <?php

 if (isset($_GET['delete']))
 {
include("config.php");

 $empid = $_GET['empid'];
 $query1= mysql_query("select * from faculty where empid='$empid'");
 $row1=mysql_fetch_array($query1);
 $image=$row["image_name"];
 unlink("../images/photos_faculty/".$image);


$sql = "DELETE FROM faculty WHERE empid = '" . $_GET["empid"] . "'";

$result = mysql_query($sql, $conn);

if($result)
{
    echo 'Data Deleted';
}else{
    echo 'Data Not Deleted';
}
mysql_close($conn);
}

 ?>

How to Delete Data From Mysql also files From Folder in php using above code i am getting

Anyone please solve this...how to get permission for deleting the image

error unlink(../images/photos_faculty/): Permission denied
  • Change your folder permission read, wright and exicute... – Nawin Mar 23 '18 at 12:29
  • 1
    See `../images/photos_faculty/`? There's __no file__ after `/`. So `$image` is empty? – u_mulder Mar 23 '18 at 12:29
  • how to check permission – Rahul Kumar Sharma Mar 23 '18 at 12:29
  • 2
    FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Mar 23 '18 at 12:30
  • 1
    Your script is at risk of [SQL Injection Attack](//stackoverflow.com/questions/60174) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](//stackoverflow.com/questions/5741187) Use [prepared parameterized statements](https://php.net/manual/en/mysqli.quickstart.prepared-statements.php). – John Conde Mar 23 '18 at 12:30
  • nlink("../images/photos_faculty/".$image); – Rahul Kumar Sharma Mar 23 '18 at 12:30
  • Where you are using in your local or server. If server means which server – Nawin Mar 23 '18 at 12:30
  • If you're on Mac/Linux, do `chmod -R 777 images` (where `images` is your `images` folder). If that fixes the problem, change the `777` to something a bit more strict. – Jeff Huijsmans Mar 23 '18 at 12:31
  • can anyone write the permission code where should i place. – Rahul Kumar Sharma Mar 23 '18 at 12:32
  • we are not talking about code...do some stuffs in google... before ask here...:( – Nawin Mar 23 '18 at 12:33
  • using local server – Rahul Kumar Sharma Mar 23 '18 at 12:33
  • windows or linux? – Nawin Mar 23 '18 at 12:33
  • linux server.... – Rahul Kumar Sharma Mar 23 '18 at 12:35
  • Check this https://stackoverflow.com/questions/3740152/how-do-i-set-chmod-for-a-folder-and-all-of-its-subfolders-and-files-in-linux-ubu – Nawin Mar 23 '18 at 12:35

0 Answers0