I have a form written in php with connection to a bank administered by phpMyAdmin.
WHAT SHOULD HAPPEN:
The data entered in the form should be registered with a alert
"saved successfully" and returning to the previous page.
WHAT'S HAPPENING:
When you try to register, you even redirect to the page responsible for registering and displaying alert
, but the page is blank, alert
does not appear, does not return to the previous page and does not register information in the database.
FORM:
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h1 style="
margin-top:100px;">Cadastro de Formações</h1>
<p> </p>
<p class="lead"></p>
<ul class="list-unstyled">
<form id="cadastro" name="cadastro" method="post" action="banco/updateF.php" style="
text-align: left;
margin-top:50px;">
<div class="col-lg-12">
<div class="form-group" style="
text-align: left;">
<label for="NOME">Nome: </label>
<input type="text" required class="form-control" id="NOME" name="NOME" placeholder="Nome da formação">
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="CARGA">Carga Horária: </label>
<input type="text" required class="form-control" id="CARGA" name="CARGA" placeholder="Carga horária da formação">
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="OBJETIVO">Objetivo: </label>
<input type="text" required class="form-control" id="OBJETIVO" name="OBJETIVO" placeholder="Objetivo da formação">
</div>
<div class="form-group" method="post" style="
text-align: left;">
<label for="CONTEUDO">Conteúdo da programático: </label>
<textarea class="form-control" id="CONTEUDO" rows="3" name="CONTEUDO" placeholder="Conteúdo programático da formação"></textarea>
</div>
<div class="">
<button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
</div>
<div class="alert alert-info" role="alert">
<strong>Hey! </strong> Antes de realizar o cadastro, certifique-se de que não se esqueceu de nada! :)
</div>
</div>
</form>
</ul>
</div>
</div>
</div>
THE CONNECTION:
<?php
mysql_connect("localhost","root","") or die ("erro na conexao com o banco de dados!");
mysql_select_db("db_formacao");
?>
UPDATE:
<!-- Envia dados do formulario de edicao pro banco de dados -->
<!--TESTE DE BANCO -->
<?php
require ("conecta.php");
//coletando dados do formulario
$nome = $_POST["NOME"];
$carga = $_POST["CARGA"];
$objetivo = $_POST["OBJETIVO"];
$conteudo = $_POST["CONTEUDO"];
// Inserir dados no banco
$itens = $_POST['NOME'];
if (!empty($itens)){
$itens = implode(',', $_POST['NOME']);
}
$up = "UPDATE turmas SET NOME = '$nome', CARGA = '$carga', OBJETIVO = '$objetivo', CONTEUDO = '$conteudo'";
echo $up;
$up= mysql_query($up) or die(mysql_error());
?>
<?php
if (mysql_affected_rows() > 0) {
echo '<script type="text/javascript">
alert("Salvo com Sucesso !");
window.history.go(-1);
</script>';
} else {
echo '<script type="text/javascript">
alert("Salvo sem Modificações !");
window.history.go(-1);
</script>';
}
?>
When I try to display the source code of this blank page through the browser, only the comments on the update page appear.
I'm not very experienced, but from what I've studied, it does not seem wrong at all. If you can tell me the mistakes, I'd appreciate it. :)