hi guys im trying to create a ajax delete script for my gallery but it doesn't seem to be deleting, instead it gives the following errors.
Warning: Division by zero in /opt/lampp/htdocs/project/others/delete_photo.php on line 20
Warning: unlink(): No such file or directory in /opt/lampp/htdocs/project/others/delete_photo.php on line 20
the delete script is as follows:
<?php
require $_SERVER["DOCUMENT_ROOT"].'/project/includes/dbconfig.inc.php';
$session= htmlentities($_SESSION['uname']);
$sess_uname= stripslashes($session);
$id0= htmlentities($_POST['id']);
$id= stripslashes($id0);
$sql="DELETE FROM photos WHERE id=':id' LIMIT 1";
$stmt=$conn->prepare($sql);
$stmt->bindparam(":id",$id);
$stmt->execute();
$sql1 = "SELECT * FROM photos WHERE user=':session' LIMIT 30";
$stmth=$conn->prepare($sql1);
$stmth->bindparam(":session",$sess_uname);
$stmth->execute();
$dir="user/$sess_uname";
$count0=$stmth->fetch(PDO::FETCH_ASSOC);
$count=count($count0);
$row1 = $stmth->fetch(PDO::FETCH_ASSOC);
if ($count>0) {
unlink($dir/$row1['filename']);
}
/*if (isset($_SESSION['app'])&&$_SESSION['uname']!="") {
header("location: ../home.php?u={$_SESSION['uname']}");
} else {
header("location: ../index.php?usernotfound?id=017");
}
*/
the ajax logic is as follows:
$("button.delete_photo").click(function(){
var del_id = $(this).attr('id');
var del_attr=$(this).attr('attr');
$.post("others/delete_photo.php",
{id:del_id},function(data){
$("."+del_id).slideUp('slow', function() {$(this).remove(data);});
}
);
});
session_start();in the beginning of your code. Ps.$dir/$row1['filename']does not do what you think it does.