1
I’m starting in PHP and I’m having problems with the following code
<?php
define("SERVIDOR", "localhost");
define("USUARIO", "root");
define("SENHA", "leonardo");
define("BANCODEDADOS", "estacionamento");
$conecta = new mysqli(SERVIDOR, USUARIO, SENHA, BANCODEDADOS); // CONECTA
if ($conecta->connect_error) {
trigger_error("ERRO NA CONEXÃO: " . $conecta->connect_error, E_USER_ERROR);
}
$curso_aluno = $_POST ["curso_aluno"];
$semestre_aluno = $_POST ["semestre_aluno"];
$nome_aluno = $_POST ["nome_aluno"];
$email = $_POST ["email"];
$celular_aluno = $_POST ["celular_aluno"];
$tipo_veiculo = $_POST ["tipo_veiculo"];
$placa_veiculo = $_POST ["placa_veiculo"];
$tipo_veiculo2 = $_POST ["tipo_veiculo2"];
$placa_veiculo2 = $_POST ["placa_veiculo2"];
$sql = "INSERT INTO alunos (curso_aluno,
semestre_aluno,
nome_aluno,
email,
celular_aluno,
tipo_veiculo,
placa_veiculo,
tipo_veiculo2,
placa_veiculo2)
VALUES ('$curso_aluno',
'$semestre_aluno',
'$nome_aluno',
'$email',
'$celular_aluno',
'$tipo_veiculo',
'$placa_veiculo',
'$tipo_veiculo2',
'$placa_veiculo2')"; // CONSULTA
$query = $conecta->query($sql); // RODA A CONSULTA
$conecta->close(); // FECHANDO A CONEXÃO
?>
What happens is that it is not saving the data of my form in the database. The form, if you wish, can be consulted at https://leoliveira.xyz/CadastroEstacionamento , and it’s like below:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Cadastro Estacionamento -</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js" type="text/javascript"></script>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap-theme.min.css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/css/bootstrapValidator.min.css"/>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/js/bootstrapValidator.min.js"></script>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<center><img src="img\logo.jpg" width="800" height="100"></center>
<div class="container">
<form class="well form-horizontal" action="inserir_dados.php" method="POST" id="cadastro_estacionamento" data-toggle="validator">
<fieldset>
<!-- Nome Formulário -->
<legend>Cadastro de veículos</legend>
<!--Curso -->
<div class="form-group">
<label class="col-md-4 control-label">Curso</label>
<div class="col-md-4 selectContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-star"></i></span>
<select name="curso_aluno" id="curso_aluno" class="form-control selectpicker" required>
<option value=" " >selecione seu curso</option>
<option>Automação Industrial</option>
<option>Gestão Empresarial</option>
<option>Gestão da TI</option>
<option>Manutenção Industrial</option>
<option>Produção Fonográfica</option>
</select>
</div>
</div>
</div>
<!-- Semestre -->
<div class="form-group">
<label class="col-md-4 control-label">Semestre</label>
<div class="col-md-4 selectContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
<select name="semestre_aluno" id="semestre_aluno" class="form-control selectpicker" required>
<option value=" " >selecione seu semestre</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
</div>
</div>
</div>
<!-- Formulário Nome-->
<div class="form-group">
<label class="col-md-4 control-label">Nome</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input name="nome_aluno" id="nome_aluno" placeholder="nome completo" class="form-control" type="text">
</div>
</div>
</div>
<!-- Formulário Email-->
<div class="form-group">
<label class="col-md-4 control-label">Email</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input name="email" id="email" placeholder="endereço de email" class="form-control" type="text">
</div>
</div>
</div>
<!-- Formulário Telefone-->
<div class="form-group">
<label class="col-md-4 control-label">Celular</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
<input name="celular_aluno" id="celular_aluno" placeholder="apenas números com ddd" class="form-control" type="text">
</div>
</div>
</div>
<!-- Formulário RA-->
<div class="form-group">
<label class="col-md-4 control-label">R.A.</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="ra_aluno" id="ra_aluno" placeholder="apenas números" class="form-control" type="text">
</div>
</div>
</div>
<!-- Tipo de veículo -->
<div class="form-group">
<label class="col-md-4 control-label">Tipo de Veículo</label>
<div class="col-md-4 selectContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-road"></i></span>
<select name="tipo_veiculo" id="tipo_veiculo" class="form-control selectpicker" required>
<option value=" " >selecione o tipo</option>
<option>Carro</option>
<option>Moto</option>
</select>
</div>
</div>
</div>
<!-- Placa do Veículo-->
<div class="form-group">
<label class="col-md-4 control-label">Placa</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-qrcode"></i></span>
<input name="placa_veiculo" id="placa_veiculo" placeholder="placa do veículo" class="form-control" type="text" required>
</div>
</div>
</div>
<!-- Tipo de veículo 2-->
<div class="form-group">
<label class="col-md-4 control-label">Possui segundo veículo?</label>
<div class="col-md-4 selectContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-road"></i></span>
<select name="tipo_veiculo2" id="tipo_veiculo2" class="form-control selectpicker">
<option value=" " >selecione o tipo</option>
<option>Carro</option>
<option>Moto</option>
</select>
</div>
</div>
</div>
<!-- Placa do Veículo 2-->
<div class="form-group">
<label class="col-md-4 control-label">Placa do segundo veículo</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-qrcode"></i></span>
<input name="placa_veiculo2" id="placa_veiculo2" placeholder="placa do segundo veículo" class="form-control" type="text">
</div>
</div>
</div>
<!-- Mensagem de conclusão -->
<div class="alert alert-success" role="alert" id="success_message">Concluído! <i class="glyphicon glyphicon-thumbs-up"></i> Dados cadastrados com sucesso.</div>
<!-- Botão Cadastrar -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-warning" >Cadastrar <span class="glyphicon glyphicon-plus-sign"></span></button>
</div>
</div>
</fieldset>
</form>
</div>
<!-- /.container -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
As can be seen on the site, the form does not return any error and shows the message that the data has been entered successfully, but nothing happens.
Welcome to [pt.so]. A good practice to start a healthy discussion is to do the [tour] if you haven’t already done it, and read the [Ask] guide. Start by following these recommendations, especially knowing what types of questions to ask, how to create a minimal example that is complete and verifiable, and even what to do when someone answers you.
– Woss
Domain has expired
– UzumakiArtanis