Jump to content

Help with getting data, then deleting them!


spyer

Recommended Posts

hey guys,, it's me again...  :-[ needing help one more time....

 

i have this table called (uploads):

 

_______ TABLE `uploads` (
  `fileid` int(10) unsigned NOT NULL auto_increment COMMENT 'File ID',
  `uploaderhash` int(10) unsigned NOT NULL COMMENT 'Uploader Hash',
  `filename` varchar(255) NOT NULL COMMENT 'File Name',
  `filemime` varchar(255) NOT NULL COMMENT 'File Mime',
  `filesize` varchar(255) NOT NULL COMMENT 'File Size',
  `uploaderip` varchar(255) NOT NULL COMMENT 'Uploader IP',
  `downlink` varchar(255) NOT NULL COMMENT 'Download Link',
  `delelink` varchar(255) NOT NULL COMMENT 'Delete Link',
  PRIMARY KEY  (`fileid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

 

This table is where uploaded file and uploader data is store.

 

uploaderhash is the uploader id, so i'll fetch_array data where uploaderhash = number(454bla bla)

 

the data will be in a table where there is a checkbox for each row, it'll look something like this

 

_FILEID_ | _FILENAME_ | _FILEMIME_ | _FILESIZE_ | _DOWNLINK_ | _DELELINK_ | /_\

 

/_\ means checkbox

 

the users will see this table for the files they've uploaded.. i want them to be able to check what ever checkbox for what ever row they want to delete and click submit button to delete the row containing the checked checkbox.

 

when SUBMIT button is clicked this will (or should ???) happen:

$sql = mysql_query("DELETE FROM uploads WHERE fileid='$i'");
//and the unlink to delete the file
$file = "../images/" . $_GET['file'];
if(file_exists($file)){
if(unlink($file)){
echo "deleted!";
}}

 

i think i made it so confusing!!  ???

 

hope you got what i want  ;)

 

thanks

Link to comment
Share on other sites

ok,, i'll show you the code

 

This is the PHP code page (gallery.php):

<?
session_start();
// #################### CHECK IF LOGGED IN #######################
if(!session_is_registered("userid")) {

// #################### IMPORTS #######################
include "classes.php";
include "config.php";
include "globals.php";

// #################### REDIRECT TO INDEX #######################
redir0 ("index.php");

	}else{

// #################### IMPORTS #######################
include "classes.php";
include "config.php";
include "globals.php";

// ############################################################
$profile = ' : <a href="' . $style['url'] . '/profile.php">' . $phrases['profile'] . '</a>';
$logout = ' : <a href="' . $style['url'] . '/login.php?do=logout">' . $phrases['logout'] . '</a>';
$your_files = ' : <a href="' . $style['url'] . '/gallery.php">' . $phrases['your_files'] . '</a>';
$logged = $phrases['user_welcome'] . " " . $_SESSION['username'];
$userhash = $_SESSION['userhashid'];

// #################### HEADER #######################
$html = block::load("temps/header.htm");
eval ("print stripslashes(\"$html\");");


// #################### DELETE FILES#######################
if($_GET['do'] = "delete"){
$res= mysql_query("Select * from uploads") or die (mysql_error());

$checkboxes=mysql_num_rows($res);

$f = $checkboxes + $checkboxes;


for($i=0;$i<=$f;$i++) if(isset($_POST[$i]))

$data2delete= mysql_query("Select * from uploads where fileid = '$i'") or die (mysql_error());

$file = "./images/" . $userhash . "/" . $_POST['filename2'] . "." . $_POST['filemime2'];

while(!$file = ""){
$sql = mysql_query("DELETE FROM uploads WHERE fileid='$i'");
if(@unlink($file)){
echo "success";
echo $file . "<br />";
}
exit;
}

}

// #################### CHECK IF USER HAS ANY FILES #######################
$chkresult = mysql_query("Select * from uploads where uploaderhash = $userhash") or die (mysql_error());

$chkrow = mysql_fetch_array($chkresult);
$chkfileid = $chkrow['fileid'];
if($chkfileid == ""){
// #################### NO FILES ERROR MSG #######################
$html = block::load("temps/nofile_err.htm");
eval ("print stripslashes(\"$html\");");
}else{
$result = mysql_query("Select * from uploads where uploaderhash = $userhash") or die (mysql_error());
// #################### UPLOADED TOP #######################
$html = block::load("temps/uploaded_view.htm");
eval ("print stripslashes(\"$html\");");

while($row = mysql_fetch_array($result)){
#echo $row['fileid']. " | " .$row['uploaderhash']. " | ".$row['filename']. " | " .$row['filemime']. " | " .$row['filesize']. " | " .$row['downlink']. " | " .$row['delelink'] ."<br />";
#	echo "<br />";
// #################### UPLOADED BOTTOM #######################
$html = block::load("temps/uploaded_view_2.htm");
eval ("print stripslashes(\"$html\");");

}
echo "</table>";
echo "<center><input type='submit' value='Submit' name='B1'></center></form>";
}


// #################### FOOTER #######################
$html = block::load("temps/footer.htm");
eval ("print stripslashes(\"$html\");");
}
?>

 

i want the users to be able to delete one or multiple files using checkboxes

 

this is the HTML code page (uploaded_view):

<br /><form name="delete" method="post" action="gallery.php?do=delete">
<table dir="rtl" style="width: 100%" cellspacing="1">
<tr style="text-align: center; font-size: xx-small" class="fjsel">
	<td style="border: 1px solid #595958; width: 30px;">Delete?</td>
	<td style="border: 1px solid #595958">File ID</td>
	<td style="border: 1px solid #595958">File Name</td>
	<td style="border: 1px solid #595958">File Type</td>
	<td style="border: 1px solid #595958">File Size</td>
	<td style="border: 1px solid #595958">Download Link</td>
	<td style="border: 1px solid #595958">Delete Link</td>
	</tr>

 

this is the HTML code page (uploaded_view_2):

<tr class="tborder">
<td align="center" style="border: 1px solid #595958; width: 30px;" class="thead"><input name="$row[fileid]" type="checkbox" id="checkbox[]" value="$row[fileid]" style=" border-width:0; background-color:transparent; color:white"></td>
	<td align="center" style="border: 1px solid #595958" class="thead">
<input type="text" onfocus="javascript: this.select()" value="$row[fileid]" style="width: 25px; text-align: center; height: 16px; border-width:0; background-color:transparent; color:white" class="boarderless"></td>
	<td align="center" style="border: 1px solid #595958" class="thead">
<input type="text" name="filename2" onfocus="javascript: this.select()" value="$row[filename]" style="width: 65px" style="text-align: center; border-width:0; background-color:transparent; color:white" class="boarderless"></td>
	<td align="center" style="border: 1px solid #595958" class="thead">
<input type="text" name="filemime2" onfocus="javascript: this.select()" value="$row[filemime]" style="width: 35px; text-align: center; border-width:0; background-color:transparent; color:white" class="boarderless"></td>
	<td align="center" style="border: 1px solid #595958" class="thead">
<input type="text" onfocus="javascript: this.select()" value="$row[filesize]" style="width: 60px; text-align: center; border-width:0; background-color:transparent; color:white" class="boarderless"></td>
	<td align="center" style="border: 1px solid #595958" class="thead">
<input type="text" onfocus="javascript: this.select()" value="$row[downlink]" style="width: 240px; text-align: center; border-width:0; background-color:transparent; color:white" class="boarderless"></td>
	<td align="center" style="border: 1px solid #595958" class="thead">
<input type="text" onfocus="javascript: this.select()" value="$row[delelink]" style="width: 240px; text-align: center; border-width:0; background-color:transparent; color:white" class="boarderless"></td>
	</tr>

 

i hope you got my point :)

 

thanks.

Link to comment
Share on other sites

$row[delelink]  << what that mean please not correct php format

 

<?php
$row['delelink'];
?>

 

$row[delelink] is a variable that outputs the Delete link for the file from the database

for HTML you should use $row[delelink]

for PHP you should use $row['delelink']

Link to comment
Share on other sites


<?php

if($_POST['submit']){

$x=$_POST['x'];

for($i=0; $i<count($x); $i++){

if(".$x[$i]."){

echo " <br> CHECKED ".$x[$i]." <br>";

}
}
  }
?>




<form method="POST" action=" ">
<br>
select file please...
<br>
<br>
redarrow1.mp3
<input type="checkbox" name="x[]" value="redarrow1.mp3">
<br><br>
redarrow2.mp3
<input type="checkbox" name="x[]" value="redarrow2.mp3">
<br><br>
<input type="submit" name="submit" value="Send">
</form>

Link to comment
Share on other sites

$row[delelink] is a variable that outputs the Delete link for the file from the database

for HTML you should use $row[delelink]

for PHP you should use $row['delelink']

 

 

 

well i never new that sure your wrong but hey only been programming for years lol.....

Link to comment
Share on other sites

sorry for the delay,

 

well,, let me explain:

Lets say i have X - Y - Z

when i select all and hit submit(DELETE)

 

it show these messages:

CHECKED 1

the file Z was deleted successfully

CHECKED 2

the file Z was deleted successfully

CHECKED 3

the file Z was deleted successfully

 

if you notice, it only deletes the last file, but showed the message 3 times for the number of files i've selected.

 

so i tried using (foreach) and it worked like a charm,,, yet a problem rose.

 

the file is not so much deleted, i think when we used (fopen) we told the script to open the file x delete what ever inside that file and (fclose) close it, so i end up with an embty file called (x,z,y etc.. whatever)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.