0

I'm trying to build an interface to insert, edit and delete records in a MySQL database, using PHP and a TinyMCE editor to insert rich text.

When I try to populate the fields in the form in the "edit" section, the TinyMCE text areas don't work. The text inputs are correctly populated with the database data, but the text areas remain empty.

I already tried to reset the TinyMCE init (I need to disable paragraphs), but nothing changes.

Here's the code of my edit page:

<html>
<head>
  <script type="text/javascript" src="tinymce/tinymce.min.js"></script>
    <script type="text/javascript">
    tinymce.init({

    selector: "textarea",
    forced_root_block : "", 
    force_br_newlines : true,
    force_p_newlines : false

 });

//validator form js
function validate_form(){
var x = document.getElementById('autore').value;
var y = tinyMCE.get('titolo').getContent();

if( x == "" || x == null || y == "" || y == null){
alert("Inserisci autore e titolo");
return  false;
}
}
</script>
</head>
<body>
<?php

include ("connessione_mysql.php");

$rows_id=$_GET["rows_id"];

$sql="SELECT * FROM bibliografia WHERE ID='$rows_id'";
$results=mysql_query($sql, $connessione_mysql);
$num_rows=mysql_num_rows($results);

if ($num_rows==0) {
    echo "Il database è vuoto";
} else {
while ($rows=mysql_fetch_array($results)) {
          $autore =$rows['autore'];
          $titolo=$rows['titolo'];
          $note=$rows['note'];
          $editore=$rows['editore'];
          $ID=$rows['ID'];
      }

echo "<form method='post' onsubmit='return validate_form()' action='script2_modifica_bibliografia.php' class='dark-matter'>";

echo "<label><span>Autore* :</span> <INPUT TYPE=\"TEXT\" NAME=\"autore\" id=\"autore\" VALUE=\"$autore\" SIZE=\"74\"></label>";
echo "<label><span>Titolo* :</span><div class=\"aggiusta\"><TEXTAREA NAME=\"titolo\" id=\"titolo\" VALUE=\"$titolo\" ROWS=\"10\" COLS=\"60\"></TEXTAREA></div></label><br>";
echo "<label><span>Note :</span><div class=\"aggiusta\"><TEXTAREA NAME=\"note\" VALUE=\"$note\" ROWS=\"10\" COLS=\"60\"></TEXTAREA></div></label><br>";
echo "<label><span>Editore :</span> <INPUT TYPE=\"TEXT\" NAME=\"editore\" VALUE=\"$editore\" SIZE=\"74\"></label>";

echo "<input type=\"hidden\" name=\"ID\" value=\"$ID\">";
echo "<label><span>&nbsp;</span><INPUT TYPE=\"SUBMIT\" VALUE=\"Modifica il record\" CLASS=\"SUBMIT\"></label>";
}

echo "</FORM>";
mysql_close($connessione_mysql);
?>

</body>
</html>
Chris Baker
  • 49,926
  • 12
  • 96
  • 115
Fefe
  • 15
  • 3

1 Answers1

0

Unlike other form elements, the textarea element does not use the value property. Instead, it is a block element, so you'd use it like this: <textarea>My value goes here</textarea>

Examples from your code: <textarea>$note</textarea> <textarea>$titolo</textarea> etc, etc

Please refer to this MDN document about the textarea element for more information: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea

Another important note, please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Chris Baker
  • 49,926
  • 12
  • 96
  • 115
  • Thank you very much. It works like a charm. I had to study on a 2002 PHP-MySQL manual, and that's the result. And thank you for your other suggestions. – Fefe Mar 26 '15 at 20:15