Valkeri2010 Posted November 8, 2010 Share Posted November 8, 2010 Hello Mates, I am in need of help. I have a Flat File News Script. I am not sure how to build the Delete script.. i am not knew to PHP but kinda new to Flat File Database.. the reason why im using FFD is because my service doesn't allow mysql on the cheaper priced web pages.. i have 4 fields ID || user_name || title || message i want it to check the id because it will be in the url like http://webpage.com/delete_news.php?id=3 and the id 3 and the other fields in id 3 is deleted. Thank you Valkeri2010 Quote Link to comment https://forums.phpfreaks.com/topic/218080-flat-file-delete/ Share on other sites More sharing options...
darkfreaks Posted November 8, 2010 Share Posted November 8, 2010 could try something like FFD Manager Quote Link to comment https://forums.phpfreaks.com/topic/218080-flat-file-delete/#findComment-1131679 Share on other sites More sharing options...
OldWest Posted November 8, 2010 Share Posted November 8, 2010 If your hosting provider is running a php version 5.0 or later, sqllite (lite) should be installed. sqlite is essentially a flat file basic database system that uses commands similar to MySQL.. That would probably be your best bet. sqlite also has its own set of specialized commands (and uses some of standard SQL as well).. http://us.php.net/manual/en/book.sqlite.php Quote Link to comment https://forums.phpfreaks.com/topic/218080-flat-file-delete/#findComment-1131682 Share on other sites More sharing options...
Valkeri2010 Posted November 10, 2010 Author Share Posted November 10, 2010 Sorry took so long to reply but been busy.. but i don't really want to switch from what i have to something i have to rebuild.. so im going to stick with what i have.. but on that note I did manage to build something that will delete. but it deletes everything in the news.db file but here is what i have. please help me.. <?php $id_to_delete = $_GET['id']; $filename = "news.db"; $lines = file($filename); $handle = fopen($filename, 'w'); foreach($lines as $line) { list($id,$userName,$title,$datetime,$message) = $explode("||", $line); if($id != $id_to_delete) { fwrite ($handle, $line); } } fclose ($handle); header("Location: delete_news.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/218080-flat-file-delete/#findComment-1132526 Share on other sites More sharing options...
PFMaBiSmAd Posted November 10, 2010 Share Posted November 10, 2010 You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php errors would be reported and displayed. You will save a ton of time. There would be an errors about an undefined variable explode and a function name must be a string in your line of code with $explode(...) because you have a $ in front of the function name explode(). I also recommend for any type of file modification operation like this that one of the first things your code does it to rename your original file to something like news.bak so that you always have an unmodified copy of the data in case something goes wrong when writing the modified output to the news.db file. Quote Link to comment https://forums.phpfreaks.com/topic/218080-flat-file-delete/#findComment-1132535 Share on other sites More sharing options...
Valkeri2010 Posted November 10, 2010 Author Share Posted November 10, 2010 wow i can't believe i missed that lol.. thank you that works Quote Link to comment https://forums.phpfreaks.com/topic/218080-flat-file-delete/#findComment-1132537 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.