lalabored Posted May 11, 2007 Share Posted May 11, 2007 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 More sharing options...
MadTechie Posted May 11, 2007 Share Posted May 11, 2007 erm.. well first change $deleteid = $key to $deleteid = $key; also whats the error ? / problem ans please use code tags Link to comment https://forums.phpfreaks.com/topic/51003-solved-deleting-using-checkboxes-stuck/#findComment-250962 Share on other sites More sharing options...
lalabored Posted May 12, 2007 Author Share Posted May 12, 2007 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. =\ Link to comment https://forums.phpfreaks.com/topic/51003-solved-deleting-using-checkboxes-stuck/#findComment-251020 Share on other sites More sharing options...
lalabored Posted May 12, 2007 Author Share Posted May 12, 2007 When I do var_dump() on $pmid it says "string(5) "Array"", did I do something wrong? Nevermind, now I have a different problem, I'm only able to delete one message at a time o.o Link to comment https://forums.phpfreaks.com/topic/51003-solved-deleting-using-checkboxes-stuck/#findComment-251024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.