Spock Posted March 9, 2011 Share Posted March 9, 2011 Hey guys, first post and I've just returned to PHP after about 4 years of no coding, so be gentle! In a nutshell I'm creating a photo album and I've pretty much got the majority of it complete, apart from a few tweaks and the obvious ongoing development. I'm at the stage now where I need to moderate images being uploaded, so I've made an admin only script which displays the uploaded images with links that say approve and delete. Uploaded images are stored in uploads/ which are left there until i move them to img/, plus the filename is stored in mysql so I can "<img src='../uploads/".$row['filename']."' width='200'>". Now, I would like to make the Approve button move the image from uploads/ to img/ and I'd like the delete button to remove both the entry from MySQL and the file from the uploads folder and I'm not too sure on how to make it work. Here's what I have so far in the mod.php file (mod for moderation) $image = mysql_query("SELECT * FROM images WHERE id"); while($row = mysql_fetch_assoc($image)) { echo " <table> <td> <tr> <img src='../uploads/".$row['filename']."' width='200'><br /> </tr> </td> <td> <tr> <a href=''>Approve</a> <a href=''>Delete</a> </tr> </td> </table> "; } You'll have to ignore the table tags, I'm still getting used to positioning items on the screen lol. Any clues would be greatly appreciated Live long and prosper. Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/ Share on other sites More sharing options...
litebearer Posted March 9, 2011 Share Posted March 9, 2011 http://webxadmin.free.fr/article/php-move-file-211.php However, really no need to move the images; just add a field to the db table, a field that is 0 or 1; 0 means the image is awaiting 'approval' so don't display to 'public', 1 means the image has been 'approved'. all the images can be in the same folder Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185234 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 Ahh so I can delete the actual image though so it doesn't waste space? Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185269 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 Link don't work, shameless bump Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185513 Share on other sites More sharing options...
litebearer Posted March 10, 2011 Share Posted March 10, 2011 Ahh so I can delete the actual image though so it doesn't waste space? My impression was, only images that you disapprove would be deleted. Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185519 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 Okay excellent, i've managed to get both the file and the mysql entry to delete, now for approving I was thinking of using UPDATE, but I'm wondering how I do so in such a way that a single image would have a value changed in mysql rather than them all. I've tried the following but it doesn't work, any ideas? $appfile=$_GET['filename']; $sql = mysql_query("UPDATE images WHERE filename='$appfile' SET approved='1'"); if ($sql) { echo "Approved!"; echo "<br />"; echo "<a href='mod.php'>Back</a>"; } else { echo "Error."; echo "<br />"; echo "<a href='mod.php'>Back</a>"; } Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185545 Share on other sites More sharing options...
litebearer Posted March 10, 2011 Share Posted March 10, 2011 1. echo $appfile to be sure it contains the value you expect. IF it does have the correct value change this... $sql = mysql_query("UPDATE images WHERE filename='$appfile' SET approved='1'"); to this... $sql = mysql_query("UPDATE images SET approved=1 WHERE filename='$appfile'"); Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185558 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 Thank you ever so much litebearer, you've been a great help. The final thing I'm struggling with now is displaying the images that have an approved value of 1 instead of 0 I thought I was being clever by using an if statement, but that just basically said if approved equals 1, then display everything So i need to rethink it //Display data $get = mysql_query("SELECT * FROM images LIMIT $start, $per_page"); $approved = mysql_query("SELECT * FROM images WHERE approved"); $fetchapproved = mysql_fetch_assoc($approved); while($row = mysql_fetch_assoc($get)) { // get data $filename = $row['filename']; echo "<div align='center'><img src='../uploads/".$filename."' / width='600px'></div>"; } Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185588 Share on other sites More sharing options...
TOA Posted March 10, 2011 Share Posted March 10, 2011 Close...change $approved = mysql_query("SELECT * FROM images WHERE approved"); to this: $approved = mysql_query("SELECT * FROM images WHERE approved=1"); Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185589 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 That just sets the variable though, how does it filter them out? Should I reuse the if statement around the whole statement? Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185594 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 Nope, that pretty much does the same thing Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185599 Share on other sites More sharing options...
TOA Posted March 10, 2011 Share Posted March 10, 2011 That just sets the variable though, how does it filter them out? Should I reuse the if statement around the whole statement? No, it says to get all(*) from images where approved is equal to one. That's what you said you wanted Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185600 Share on other sites More sharing options...
litebearer Posted March 10, 2011 Share Posted March 10, 2011 try... $result = mysql_query("SELECT filename FROM images WHERE approved=1"); while($row = mysql_fetch_array($result)) { ?><div align='center'><img src='../uploads/<?PHP echo $row['filename']; ?>' width='600px'></div><?PHP } Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185603 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 Ahhh, what I mean is I'm trying to get display 1 approved image per page so you can navigate with previous and next buttons, the other way displayed all the approved images on the one page. Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185607 Share on other sites More sharing options...
TOA Posted March 10, 2011 Share Posted March 10, 2011 Ahhhhhhh. You need pagination... There's plenty of tutorials here at phpfreaks and also on google. They'll be easy to find. Basically you set an offset and use LIMIT to return what you want. Look into it Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185615 Share on other sites More sharing options...
litebearer Posted March 10, 2011 Share Posted March 10, 2011 display one per page - http://www.nstoia.com/sat/disp_pag/one.php Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185618 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 I've already set up pagination, at the moment it will display everything (one per page) that is in uploads/ however I only want it to display the images marked with a 1 in approved Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185640 Share on other sites More sharing options...
litebearer Posted March 10, 2011 Share Posted March 10, 2011 try changing this... $get = mysql_query("SELECT * FROM images LIMIT $start, $per_page"); to this... $get = mysql_query("SELECT * FROM images WHERE approved=1 LIMIT $start, $per_page"); and get rid of the other query Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185668 Share on other sites More sharing options...
Spock Posted March 10, 2011 Author Share Posted March 10, 2011 That sort of works, it only displays the images with approved set to 1, however you can still navigate for the images it doesn't display...I think I might do it the way I originally thought and move the file to a different folder, it'll probably be simpler lol Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185845 Share on other sites More sharing options...
litebearer Posted March 10, 2011 Share Posted March 10, 2011 perhaps we need to look at the pagination script Quote Link to comment https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/#findComment-1185886 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.