I have a script that allow's user's to upload image's into albums.
The Album name , password , and title are stored in a table called albums.
But detail's about the physical path to the server and the image location's are stored in a table called upload_image_details.
User's can delete or edit thier albums using edit_album.php , But when the Delete OP is issued thru a Get command , If the user doesnt have any album's , then EVERY Record in the Entire upload_image_detail's table is being removed , all user's data get's deleted. Basiclly ... if the user hit's delete , and they dont have an album , the script doesnt find an album to delete , so it's removing all data in upload_image_details. Thier must be a fix for this .. Please help , below is the code
<?php
include("./admin/config.php");
include("$include_path/common.php");
global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SESSION_VARS;
global $_SESSION;
if ($HTTP_POST_VARS!="")
$_POST=$HTTP_POST_VARS;
if ($HTTP_GET_VARS!="")
$_GET=$HTTP_GET_VARS;
if ($HTTP_SESSION_VARS!="")
$_SESSION=$HTTP_SESSION_VARS;
check_user_login();
if ($_GET['op'] == 'edit')
{
include("$include_path/$table_file");
include("$include_path/doc_head.php");
include("$include_path/styles.php");
include("$include_path/custom.php");
include ("Ads_new.php");
$album_results = mysql_query("SELECT * FROM $tb_albums WHERE user_id='".$_SESSION['userid']."' AND id='".$_GET['aid']."'");
$a_row = mysql_fetch_array($album_results);
$tpl->assign(array(
'ALBUM_TITLE' => $a_row['title'],
'ID' => $a_row['id']
));
$tpl->parse('CONTENT', 'albums_edit');
$content = $tpl->fetch('CONTENT');
$final_output = table(" Albums Management", $content);
$tpl->assign(array('CONTENT_TEXT' => $final_output));
$tpl->parse('PAGE', 'main');
$final_output = $tpl->fetch('PAGE');
$final_output = final_output($final_output);
include ("copy.php");
}
elseif ($POST['op'] == 'edit2')
{
if ($POST['title'])
{
if ($POST['password'] && !$POST['public'])
{
$pass = ",password='".$POST['password']."'";
}
elseif ($POST['public'])
{
$pass = ",password=''";
}
if (mysql_query("UPDATE $tb_albums SET title='".$POST['title']."'".$pass." WHERE user_id='".$SESSION['userid']."' AND id='".$POST['id']."'"))
{
header("Location: albums.php");
}
else
{
die(mysql_error());
}
}
}
// CODE THAT IS DELETING ALL DATA FROM UPLOAD_IMAGE_DETAILS if the user doesnt have an album
elseif ($GET['op'] == 'delete')
{
$pic_result = mysql_query("SELECT * FROM $tb_upload_image_details WHERE album_id='".$GET['aid']."'");
while ($p_row = mysql_fetch_array($pic_result))
{
$filename = "";
$res = mysql_query("select concat(id, '$id') as image, image_ext from $tb_users where id = '".$SESSION['userid']."'");
if ($data=mysql_fetch_row($res))
{
$filename=$data[0];
$extension=".".$data[1];
}
$file = $image_path . "/" . $filename;
$res = mysql_query("select ext from $tb_image_types");
$flag = 0;
while ($data = mysql_fetch_row($res))
{
$ext=$data[0];
$deletefile=$file.$p_row['total_file_count'].'.'.$ext;
if (@unlink($deletefile))
{
$extension1=".".$ext;
$flag++;
break;
}
}
mysql_query("DELETE FROM $tb_upload_image_details WHERE id='".$p_row['id']."'");
}
mysql_query("DELETE FROM $tb_albums WHERE id='".$GET['aid']."'");
header("Location: albums.php");
}
else
{
die("unknown operation");
}
?>