Reputation: 13
I am having a rather strange issue and for the likes of me, cannot figure it out!
Basically, I have users who are allowed to upload documents, which are then associated with their profile.
If the user decides to delete a document, the only thing that gets deleted here, is the document, but not the content included, e.g. comments, title, etc - it's as if nothing ever happened - except of course - the physical document has been deleted - sql entries however have not.
mydocs.php:
if ($_SESSION['USERID'] != "" && $_SESSION['USERID'] >= 0 && is_numeric($_SESSION['USERID']))
{
if($_REQUEST['submitdelete']!="")
{
$deletedoc = $_POST['deletedoc'];
$svcount = count($deletedoc);
for ($i = 0; $i < $svcount; $i++)
{
if ($deletedoc[$i] != "" && $deletedoc[$i] >= 0 && is_numeric($deletedoc[$i]))
{
$query = "SELECT * FROM docs WHERE DID='".mysql_real_escape_string($deletedoc[$i])."'";
$executequery = $conn->execute($query);
$theuserid = $executequery->fields['USERID'];
$doc_name = $executequery->fields['doc_name'];
if(mysql_affected_rows()>=1)
{
$docpath = $config['docdir']."/".$doc_name;
@chmod($docpath, 0777);
if (file_exists($docpath))
{
@unlink($docpath);
}
if($theuserid == $_SESSION['USERID'])
{
$deletefrom[] = "docs";
$deletefrom[] = "docs_comments";
$deletefrom[] = "docs_favorited";
for($j=0;$j < count($deletefrom);$j++)
{
$query = "DELETE FROM ".$deletefrom[$j]." WHERE DID='$deletedoc[$i]'";
$conn->Execute($query);
}
$tempthumbs = $config['thumbdir']."/".$deletedoc[$i].".jpg";
if(file_exists($tempthumbs))
{
@unlink($tempthumbs);
}
if ($svcount > 1)
{
$message = $lang['643'];
}
else
{
$message = $lang['644'];
}
}
else
{
if ($svcount > 1)
{
$error = $lang['645'];
}
else
{
$error = $lang['646'];
}
}
}
}
}
}
mydocs.tpl:
<form id="deleteform" name="deleteform" action="{$baseurl}/mydocs.php" method="post">
{section name=i loop=$docs}
{insert name=seo_clean_titles assign=title value=a title=$docs[i].title}
<div class="column {if $smarty.section.i.iteration % 6 == 0}last{/if}">
<div class="image"><a href="{$baseurl}/doc/{$docs[i].DID}/{$title}"><img src="{$vthumburl}/{$docs[i].doc_name|truncate:-4:"":true}.jpg" alt="{$docs[i].title|stripslashes|truncate:25:"...":true}" ></a></div>
<h3><a href="{$baseurl}/doc/{$docs[i].DID}/{$title}">{$docs[i].title|stripslashes|truncate:17:"...":true}</a>
<br />{$lang485}: <input type="checkbox" name="deletedoc[]" value="{$docs[i].DID}">
<br /><a href="{$baseurl}/mydocsedit.php?DID={$docs[i].DID}">{$lang318}</a></h3>
</div>
{/section} <div class="btndelete">
<input type="submit" value=" " name="submitdelete"></div>
</form>
Urgently awaiting a solution / assistance.
Many thanks in advance!
Upvotes: 0
Views: 96
Reputation: 13
There is nothing wrong with the code.
For some reason, the connect.php was using write only permissions to the sql db.
Change it to All Privileges and now it works.
Now to secure it.
Upvotes: 1