Current location: Hot Scripts Forums » Programming Languages » PHP » Simple WHILE loop with unlink confusion


Simple WHILE loop with unlink confusion

Reply
  #1 (permalink)  
Old 03-12-10, 02:07 AM
ben_johnson1991 ben_johnson1991 is offline
Newbie Coder
 
Join Date: Dec 2009
Posts: 11
Thanks: 4
Thanked 0 Times in 0 Posts
Simple WHILE loop with unlink confusion

Hey,
Part of my account deletion, I obviously want all items related to that user to be removed.
This includes from all the tables and and folders and images.

this while loop is supposed to delete all 'event' folders they manage and including the photo inside of it. and then obviously being deleted from the member table and event table, where there are generaly 3 link events to one member.


This is my current script.
All important parts are in bold
PHP Code:

if(isset($_POST['delete'])){

 
$del_pass $_POST['del_pass'];
 
$del_pass md5($del_pass);
$mem_id $_SESSION['id'];
 
$get_pass mysql_query("SELECT * FROM members WHERE mem_id='$mem_id' AND password='$del_pass'");
////////////
 
$pass_num mysql_num_rows($get_pass);
  if(
$pass_num == 1){
   
$mem_id $_SESSION['id'];
     
      
$event_get mysql_query("SELECT * FROM events WHERE mem_id='$mem_id'");
     if(
mysql_num_rows($event_get) > 0){
      while(
$delrow mysql_fetch_array($event_get)){
       
$event_id $delrow['event_id'];
      
$eventfile .= 'events/$event_id/image01.jpg';
     if (
file_exists($eventfile)) {
     
unlink($eventfile);
     
rmdir($events/$event_id);
      }
      }
     
$sql_del_event mysql_query ("DELETE FROM event WHERE mem_id='$mem_id'");
     }
  }else{
  
$errorMsg '<span style="color:#F00; font-weight:bold">Delete Error:</span> Please check errors in the Password Section.';
  
$delError1 '* <span style="color:#F00; font-weight:bold">Password</span> was not Corrent<br />';
  }

I rarely use while loops apart from recieve most data from a table.

But what this is supposed to do is check through the event table and find the event_id that the member owns, and on every one that it owns, delete the image (image01.jpg in that 1 folder (events/$event_id) and then delete the folder and finally deletes all the entries from that mmber.

I hope this makes sense?
and I know it's not that hard, but I can't set it out, and a the moment, when this is submitted, nothing is deleted at all.

Thanks for any help!!
Ben.

Last edited by wirehopper; 03-12-10 at 07:05 AM. Reason: PHP tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-12-10, 07:06 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
$eventfile .= 'events/$event_id/image01.jpg';

should be

$eventfile .= "events/$event_id/image01.jpg";

The double quotes tell PHP to evaluate any variables inside the string, single quotes use the string literally.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
ben_johnson1991 (03-12-10)
  #3 (permalink)  
Old 03-12-10, 04:30 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
It shouldn't have the (.) either.

$eventfile = "events/$event_id/image01.jpg";

Because if it did, you would be looking for files that looked like.

events/$event_id/image01.jpgevents/$event_id/image01.jpgevents/$event_id/image01.jpgevents/$event_id/image01.jpgevents/$event_id/image01.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
ben_johnson1991 (03-12-10)
  #4 (permalink)  
Old 03-12-10, 07:27 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
You can use echo to display stuff while you're working on it - makes it easier to see what's happening.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
ben_johnson1991 (03-12-10)
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A few simple scripts aaroninwv Script Requests 6 03-20-08 12:01 PM
Iterating Associative arrays with foreach divya PHP 13 11-21-07 02:12 PM
infinite loop versus guarded blocks UnrealEd Everything Java 0 11-11-07 03:53 PM
Update multiple rows outside loop - need help ElvansX PHP 1 12-03-06 02:55 AM
While loop jaishalg PHP 1 11-23-04 04:36 PM


All times are GMT -5. The time now is 01:53 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.