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

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

post-code.php:

<?php
include "conn.php";

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

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

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


if(!$resultinsert){

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

?>

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

2 Answers

-1
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;
-1
Wiimm On

Quote $code1

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