1

I have the following code. This is used on my admin panel for administrators to put their notes in so the other admins can read it. I don't want to store this in a database.

The issue is the form is not saving the text in the textarea.

<?php
IF (ISSET($_POST["submit"])) {
$string = '<?php 
$notes = "'. $_POST["notes"]. '";
?>';

$fp = FOPEN("includes/notes.php", "w");
FWRITE($fp, $string);
FCLOSE($fp);
echo '<div class="ok">' . $lang["done"] . '</div>';
}

include("includes/notes.php");
?>
<form action="" method="post" id="notesform">
<textarea placeholder="Admin notes" class="notes" id="notes"><?php echo $notes; ?></textarea>
<input type="submit" value="OK">
</form>

What is going wrong? How can I fix this? I have tried most suggestions on Google but it keeps happening!

John Doe
  • 35
  • 7

2 Answers2

3

You did not give name attribute to submit button.

When we submit a form to PHP, only elements get posted with a name attribute.

So, your code is not entering:

IF (ISSET($_POST["submit"])) { // Not satisfying this condition.

Corrected code:

<input type="submit" value="OK" name="submit">

Apply the same for text area also.

Pupil
  • 23,834
  • 6
  • 44
  • 66
2

You had not given name="notes" to text-area and submit button name. Here is the complete correct code. Try this:

<?php
IF (ISSET($_POST["submit"])) {
$string = $_POST["notes"];

$fp = FOPEN("includes/notes.php", "w");
FWRITE($fp, $string);
FCLOSE($fp);
echo '<div class="ok">' . $lang["done"] . '</div>';
}

include("includes/notes.php");
?>
<form action="" method="post" id="notesform">
<textarea placeholder="Admin notes" class="notes" name="notes" id="notes"><?php echo $notes; ?></textarea>
<input type="submit" name="submit" value="OK">
</form>
Amit Rajput
  • 2,061
  • 1
  • 9
  • 27