-1

I have some code for a type of note making thing:

<h1>Notes About the rebellion:</h1>
<form action="index.php" method='post'>
Subject:<br><textarea name='textblock'></textarea><br>
Note:<br><textarea name='textblock2'></textarea><br>
<input type='submit' value='Add text'>
</form>
<iframe src="text.txt"></iframe>
<?php

// Open the text file
$f = fopen("text.txt", "a");

// Write text
fwrite($f, $_POST["textblock"] . ":" . PHP_EOL); 
fwrite($f, $_POST["textblock2"] . PHP_EOL . "\r\n"); 
//fwrite($f, $_POST["textblock"] . "\r\n");
// Close the text file
fclose($f);

// Open file for reading, and read the line
$f = fopen("text.txt", "r");

// Read text
echo fgets($f); 
fclose($f);

?>

Basically, I want when I type "/clear" in the second html form input, and submit it, the text file "text.txt" will be either deleted or cleared.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
Terry Anderson
  • 89
  • 2
  • 10

1 Answers1

0

This will do what exactly you want.

<h1>Notes About the rebellion:</h1>
<form action="index.php" method='post'>
Subject:<br><textarea name='textblock'></textarea><br>
Note:<br><textarea name='textblock2'></textarea><br>
<input type='submit' value='Add text'>
</form>
<iframe src="text.txt"></iframe>
<?php

// Open the text file
$f = fopen("text.txt", "a");

// Write text
fwrite($f, $_POST["textblock"] . ":" . PHP_EOL); 
fwrite($f, $_POST["textblock2"] . PHP_EOL . "\r\n"); 
//fwrite($f, $_POST["textblock"] . "\r\n");
// Close the text file
if($_POST["textblock2"]=="/clear"){
  fclose($f);                       //for clearing text in file
  $f = fopen( 'filelist.txt', 'w' ); //for clearing text in file
  fclose($f);              
  delete("text.php");  //for deleting file
}
else{
  fclose($f);
}
// Open file for reading, and read the line
$f = fopen("text.txt", "r");

// Read text
echo fgets($f); 
fclose($f);

?>
Sailesh Kotha
  • 1,939
  • 3
  • 20
  • 27