I have a textarea whose contents I want to post to a database.

 <div class="container">
   <div class="row">
     <form action="post-code.php" method='POST'>
     <textarea name="textEditor" id="textEditor"></textarea>
     <input type="submit">


include "conn.php";

$code1 = $conn->real_escape_string($_POST['textEditor']);

$insert = "INSERT INTO Code_Stream (Code) VALUES ($code1)";

$resultinsert = $conn->query($insert);


  echo $conn->error;
  echo "<p> Code is streaming... </p>";


It keeps on telling me that the index 'textEditor' is undefined.

2 Answers

Community On

Try to store the value of the textarea in a var and use the variable to send data to the database :

var text = document.getElementById("textEditor").value;
Wiimm On

Quote $code1

$insert = "INSERT INTO Code_Stream (Code) VALUES (\"$code1\")";
                                                  ^^      ^^