0
I have a form written in php with connection to a database administered by phpMyAdmin.
WHAT SHOULD HAPPEN:
The data entered in the form should be registered showing a alert
of "successfully saved" and back to the previous page.
WHAT’S GOING ON:
When trying to register, even redirects to the page responsible for registering and show the alert
, but the page is blank, no one appears alert
, does not return to the previous page or register the information in the bank.
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");
?>
THE 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 by the browser only the comments of the update page appear.
I’m not very experienced, but from what I’ve studied, it doesn’t seem wrong. If you could point out the mistakes, I’d really appreciate it. :)
What version of php?
– Francisco
This is something I forgot to mention. My php version is old and as there are many systems running in this version, I can’t update.
– Mariana Bayonetta
Mariana, please don’t keep adding HELP in the title, just the fact you asked on the site we already understand that you need help with your problem.
– user28595
Ta, I was going to take off after a few minutes.
– Mariana Bayonetta
But you cannot do this simply in order to "raise" the question. If the answers have not solved the problem, comment below them. Or edit the question by providing more details. You can also read [Ask] to learn how to improve the question.
– user28595
Yes, but I’m already providing all the details, I’ve commented below the answers, I’m studying, trying to solve but I can’t find the problem and it’s been a few days. I know no one has an obligation to answer me, it was just an attempt.
– Mariana Bayonetta