Jump to content

Editing and updating text files


addyp

Recommended Posts

Hey guys, im new hear so im not shore how things work.

Iv got a project where we are ment to alow users to record a bug fault in a computer, currently i have a page that looks like ths:

<?php

if (empty($_POST['bug_ID']))

echo "<p>You must enter a BUG ID number</p>";

else {

$bugID = addslashes($_POST['bug_ID']);

$name = addslashes($_POST['bug_name']);

 

umask(0007);

if (!file_exists("../../data/lab05"))

mkdir("../../data/lab05", 02777);

$lab05 = fopen("../../data/lab05/". "$bugID.txt", "a");

 

if (is_writable("../../data/lab05/NewBug.txt"))

{

if (fwrite($lab05, $bugID . ", " . $name . "\n"))

echo "<p>Thank you entering a new bug</p>";

else

echo "<p>Cannot add bug</p>";

}

else

echo "<p>Cannot write to the file.</p>";

fclose($lab05);

}

?>

 

this code runs fine however I also need to write a sperate page that allows for users to search and up date bugs recorded, I want them to search using the bug_ID field and we are ment to use the fgets method but am unshore, anyhelp would be much apricated.

 

thank you

Link to comment
https://forums.phpfreaks.com/topic/214252-editing-and-updating-text-files/
Share on other sites

Im not looking for an easy out, just someplace to start, currently this is what i have

<?php

$Search = addslashes($_POST['bug_ID']);

 

$handle = fopen ("/tmp/$Search.txt", "r");

while (!feof($handle))

{

    $buffer = fgets($handle, 4096);

    if (file_exists(rtrim($Search,"\n")))

{

        echo $buffer;

    }

else

{

        echo $buffer." has been removed.";

}

}

fclose ($handle);

?>

however it is resulting in an infantent loop. i am just unsure how to use these methods

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.