-1

In PHP, how do I echo out the value of a textarea? The code I have below doesn't work.

<form name="code_editor" action="index.php" method="post">
  <textarea name="code" rows="8" cols="80"></textarea>
  <input type="submit" value="Upload">
</form>

I have this in a separate file named 'index.php' and the code above is in 'index.html'

<?php
  echo $_POST['code_editor'];
?>
  • The name attribute of the field is meant to be referred to get the data regarding the field. You don't need to name your form by the way. and my advice to you do not name index.html and index.php in the same website. – Amr Aly Mar 04 '17 at 00:00

1 Answers1

0

You need to grab the actual field you're trying to echo.

<?php
  echo htmlspecialchars($_POST["code"]);
?>

edit: I added "htmlspecialchars" for security. Not technically required but make sure you do this.

Tyler Pope
  • 260
  • 1
  • 2
  • 15