The Tinymce editor before being a "rich text" editor is a normal form, so if you want to edit it you must convert the <
and >
for <
and >
, as in the example:
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({ selector:'#texto' });</script>
</head>
<body>
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$query = 'SELECT postagem FROM tabela WHERE id=1';
if ($result = $mysqli->query($query)) {
if($row = $result->fetch_assoc()) {
$variavelDoBanco = $row["postagem"];
}
}
?>
<form method="POST" action="arquivo.php">
<textarea id="texto" name="texto"><?php echo htmlspecialchars($variavelDoBanco); ?></textarea>
<br>
<button type="submit">Salvar</button>
</form>
</body>
</html>
Note if using Laravel with Blade will not be necessary to use htmlspecialchars
, for the {$var}
already encodes, follows an example:
Controller:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
public function editar()
{
return view('editor', [ 'postagem' => '<b>foo</b> bar <s>baz</s>' ]);
}
}
Template editor.blade.php:
<form method="POST" action="/editar">
<textarea id="texto" name="texto">{$postagem}</textarea>
<br>
<button type="submit">Salvar</button>
</form>
Note being PHP I used the API mysqli
the old api mysql_
this discontinued and was removed in PHP7
Old API documentation that informs this:
Useful links:
PLEASE, justify the downvote... is because I answered a question that this in the analysis queue? PLEASE If there’s something wrong, explain it to me so I can get better
– Guilherme Nascimento
I think I got it, the downvote seems fair, I’ll edit... I just wish they’d explain the downvotes, I never really get upset, as long as they explain... I never had a tantrum (returned) because I took downvote when they explain to me why
– Guilherme Nascimento
Ready edited, I do not know what language the AP uses, but if edit and inform later I edit with another example. What makes me upset is that the person comes to give the downvote, thinks I’m a person who gets in a tantrum and does not inform me the problem of the answer... Please understand, I am one of the most supportive of the Stack Overflow model, if the downvote is fair I will totally agree and will not be attacking anyone... The idea is always to get better if it’s bad.
– Guilherme Nascimento
I reversed the downvote and gave up, I was leaving for lunch and I forgot to comment, but the answer made no sense with the question before.
– Luis Henrique
@Luishenrique thanks for commenting :) - I think I managed to understand the problem, if there is something else that I can improve or that you think this wrong can negatively and comment, this is part of the system and I promise to try to fix what is possible!
– Guilherme Nascimento
Just to complement, I’m using Laravel, but I believe that this information would not be relevant considering the content of the question. So to get the post I use: $post = Post::find($id);
– Neimeg
@Neimeg will post an example of Laravel, just tell me the version. Note that Lade does not need because it uses a function called
e
.– Guilherme Nascimento
@Guilhermenascimento, it’s Laravel 5.2
– Neimeg
@Neimeg I haven’t used Laravel for some time, but I believe it was correct, if something is wrong please let me know.
– Guilherme Nascimento