The code without the text editor writes to the database. After I've placed the editor, the form's submit button does not send data. I'm also interested in recording snippets of programming codes. Below is the form code.
<?php
if(!isset($_SESSION)) {
session_start();
}
if(empty($_SESSION['username'])){
session_destroy();
header('Location: index.php'); exit;
}
include_once 'modules/crud_resposta.php';
?>
<html lang="pt-br">
<head>
<?php include('templates/head_content.html.php'); ?>
<title>Início</title>
</head>
<body>
<?php
?>
<?php include('templates/navbar.html.php'); ?>
<?php include('templates/header.html.php'); ?>
<script src="//tinymce.cachefly.net/4.2/tinymce.min.js"></script>
<script>
tinymce.init({selector:'textarea',
plugins: 'code'});
</script>
<div class="row">
<div class="col-lg-12">
<h3 class="text-center">Responder Discussão</h3>
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<form method="post">
<div class="row control-group">
<div class="form-group col-xs-12 floating-label- form-group controls">
<label>Conteúdo:</label>
<textarea rows="5" class="form-control ckeditor" placeholder="resposta" name="conteudo" required data-validation-required-message="Favor, insira a resposta."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" name="inserir" class="btn btn-success btn-lg">Responder</button>
<button class="btn btn-danger btn-lg">Cancelar</button>
</div>
</div>
</form>
</div>
</div>
</div>
<?php
include('templates/footer.html.php');
?>
</body>
</html>
And below is the snippet of the CRUD code.
if(isset($_POST['inserir'])){
$conteudo_resposta = trim($_POST['conteudo']);
$conteudo = mysqli_real_escape_string($conexao, $conteudo_resposta);
$data_criacao = date('Y-m-d H:i:s');
$id_usuario = $_GET['usuario'];
$id_discussao = $_GET['discussao'];
$inserir_resposta = mysqli_prepare($conexao, "INSERT INTO resposta(conteudo, data_criacao, id_discussao, id_usuario) VALUES(?,?,?,?)");
if($inserir_resposta){
mysqli_stmt_bind_param($inserir_resposta, "ssii", $conteudo, $data_criacao, $id_discussao, $id_usuario);
mysqli_stmt_execute($inserir_resposta);
mysqli_stmt_close($inserir_resposta);
?>
<script>return alert('Resposta inserida com sucesso!');</script>
<?php
header('Location:respostas.php?discussao=' .$id_discussao);
}
else{
?>
<script>alert('Erro ao efetuar a resposta!');</script>
<?php
die(mysqli_error($conexao));
}
if(!$inserir_resposta){
die(mysqli_error($conexao));
}
}