Jump to content

[SOLVED] Deleting Using Checkboxes (Stuck)


lalabored

Recommended Posts

I'm using a flat file database and I'm trying to use checkboxes to delete data from my database but it's not working.

 

This is what my private messages database looks like... (the first part is the id of the message)

 

4tetl4xrmyux||Person Sending||Person Recieving||Subject||message||May 5 2007 at 11:41 PM||05/05/2007||

4tetl4xrmyux||Person Sending||Person Recieving||Subject||blah blah||May 5 2007 at 11:41 PM||05/05/2007||

 

My checkboxes are like this...

 

<input type="checkbox" name="pm[]" value="<?php echo $code; ?>">

 

$code is for the id of the message.

 

If I use a foreach thing like this...

 

if(isset($_POST['pm'])){
$blahblah = file("pm.php");
foreach($_POST['pm'] as $pmkey=>$pmid){
foreach($blahblah as $key=>$val){
list($code) = explode("||",$val);
if($pmid = $code){
$deleteid = $key
break;
}
}
if(!empty($deleteid) and is_int($deleteid)){
unset($blahblah[$deleteid]);
$newblah = implode("\n",$blahblah);
}
}
$fh = fopen("pm.php","w") or die("Error: Cannot open file.");
fwrite($fh,$newblah);
fclose($fh);
}

 

What's wrong with it? Because it doesn't work...

Link to comment
https://forums.phpfreaks.com/topic/51003-solved-deleting-using-checkboxes-stuck/
Share on other sites

I'm using this code now...

 

<?php

if(isset($_POST['pm'])){
$blahblah = file("data/pmsg.db.php");
foreach($_POST['pm'] as $pmkey=>$pmid){
foreach($blahblah as $key=>$val){
list($code) = explode("||",$val);
if($pmid == $code){
$wahwah = $key;
break;
}
}
if(!empty($wahwah) and is_int($wahwah)){
unset($blahblah[$wahwah]);
$newblah = implode("\n",$blahblah);
}
}
$fh = fopen("data/pmsg.db.php","w") or die("Error: Cannot open file.");
fwrite($fh,$newblah);
fclose($fh);
}

?>

 

After I click the delete button, nothing happends. No messages are deleted.

 

Also, when I do var_dump() on $newblah, it comes out as NULL. =\

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.