spyer Posted February 16, 2008 Share Posted February 16, 2008 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 Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted February 16, 2008 Share Posted February 16, 2008 everything looks ok. As a safety measure I also put a "LIMIT 1" on the end of my SQL delete statements. That way if you make a mistake you are only deleting 1 item. Just more of a safe practice thing on my part. By no means is it necessary. Quote Link to comment Share on other sites More sharing options...
spyer Posted February 16, 2008 Author Share Posted February 16, 2008 no, i want the users to be able to delete whatever files they want.. so if 5 checkboxes were checked.. 5 are deleted. Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted February 17, 2008 Share Posted February 17, 2008 Ok. then don't put a limit 1 on the end. I was just saying that as a measure of precaution when you are testing your own website. Hope it all works out for you. Quote Link to comment Share on other sites More sharing options...
spyer Posted February 17, 2008 Author Share Posted February 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
spyer Posted February 17, 2008 Author Share Posted February 17, 2008 anyone? Quote Link to comment Share on other sites More sharing options...
spyer Posted February 18, 2008 Author Share Posted February 18, 2008 up Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 18, 2008 Share Posted February 18, 2008 $row[delelink] << what that mean please not correct php format <?php $row['delelink']; ?> if(!session_is_registered("userid")) { << what this old programming <?php if(!$_SESSION['userid')) { ?> Quote Link to comment Share on other sites More sharing options...
spyer Posted February 18, 2008 Author Share Posted February 18, 2008 $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'] Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 18, 2008 Share Posted February 18, 2008 <?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> Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 18, 2008 Share Posted February 18, 2008 $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..... Quote Link to comment Share on other sites More sharing options...
spyer Posted February 18, 2008 Author Share Posted February 18, 2008 lol,, i'm sorry, but i'm new at this, and i need a lot of help thanks for your help i'll try it Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 18, 2008 Share Posted February 18, 2008 here you got Quote Link to comment Share on other sites More sharing options...
spyer Posted February 18, 2008 Author Share Posted February 18, 2008 hey m8s, the one you gave me redarrow did work database wise, but the file deletion is not it only deletes all checked rows from databast + 1 file only, the rest files will stay Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 18, 2008 Share Posted February 18, 2008 trie this mate http://freesingles.ath.cx/cheek.php Quote Link to comment Share on other sites More sharing options...
spyer Posted February 18, 2008 Author Share Posted February 18, 2008 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.