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
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

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.