Jump to content

Flat File Delete


Valkeri2010

Recommended Posts

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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