You’re not saving in the database

Asked

Viewed 66 times

1

I’m learning to code in PHP, Analyze my codes and help me see what I’m missing, because it’s not saving in the database.

Home page where I register - Sign up.html

<!DOCTYPE html>
<html>
  <head>
    <title>Cadastro de Clientes</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="bootstrap/css/style.css">
    <script src="bootstrap/js/bootstrap.js"></script>
    </head>
    <body>
         <div align="center" class="banner">
        <img src="img/Banner Giga.jpg">
         <form method="post" action="processa.php">
             <h1>Cadastro de Clientes</h1>
             <label>Nome:</label> <input type="text" class="campo" name="nome" required placeholder="Digite seu Nome:" maxlength="100"/><br><br>
             <label>Telefone:</label> <input type="text" class="campo" name="telefone" placeholder="Digite seu Telefone" maxlength="14"/><br><br>
             <label>Bairro:</label> <input type="text" class="campo" name="bairro" placeholder="Digite o seu Bairro" maxlength="100"/><br><br>
             <label>Rua:</label> <input type="text" class="campo" name="rua" placeholder="Digite sua Rua" maxlength="100"/><br><br>
             <label>Numero:</label> <input type="text" class="campo" name="numero_casa" placeholder="Numero da Casa" maxlength="100"/><br><br>
             <input type="submit"  name="submit" value="Salvar"   class="btn btn-danger">
             <input type="reset"   value="Limpar"  class="btn btn-danger">
             </form>
        </body>
        </html>

Database Connection - Connection.php

<?php
$hostname= "localhost";
$user = "root";
$password = "";
$database = "gigabyte";
$conexao = mysqli_connect($hostname,$user,$password,$database);
mysqli_select_db($conexao,$database);
if(!$conexao){
    echo "Falha na conexão com o Banco de Dados";

}
?>

Validations to save to Database - processes.php

<?php
include_once("conexao.php");
 $nome = filter_input(INPUT_POST,'nome');
 echo "Nome: $nome <br>";
 $telefone =filter_input(INPUT_POST,'telefone');
 echo  "Telefone: $telefone<br>";
 $bairro =filter_input(INPUT_POST,'bairro' );
 echo  "Bairro: $bairro<br>";
 $rua =filter_input(INPUT_POST,'rua' );
 echo  "Rua: $rua<br>";
 $numero =filter_input(INPUT_POST,'numero_casa');
 echo  "Numero: $numero<br>";
$result="INSERT INTO clientes (nome,telefone,bairro,rua,numero_casa) VALUES('',$nome', '$telefone', '$bairro', '$rua', '$numero'))";
$resultado= mysqli_query($conexao, $result);
if($result == true){
    echo "Cadastrado com Sucesso!";
}else{
    echo "Opa, Algo de errado não está certo";
}


?>
  • Welcome to the Stackoverflow in Portuguese. Do the [tour] to learn how the community, also visit [help] to make good use of the site.

  • Are you returning error? In the file parses.php in the variable $result has one left parentheses ... '$numero'))";

  • 1

    Besides being left over in the parentheses, this '' before $nome in the VALUES is left over: $result="INSERT INTO clientes (nome,telefone,bairro,rua,numero_casa) VALUES('',$nome', '$telefone', '$bairro', '$rua', '$numero'))";

  • It’s not working yet :(

  • You are not returning any error, but when I insert the data in my HTML and click save and I will look in the database, there is nothing saved there.

  • What web server are you using? Apache? Browse the log file to see what error is happening.

Show 1 more comment

1 answer

0

Do the following

<?php

include_once("conexao.php");
$nome = filter_input(INPUT_POST,'nome');
echo "Nome: $nome <br>";
$telefone =filter_input(INPUT_POST,'telefone');
echo  "Telefone: $telefone<br>";
$bairro =filter_input(INPUT_POST,'bairro' );
echo  "Bairro: $bairro<br>";
$rua =filter_input(INPUT_POST,'rua' );
echo  "Rua: $rua<br>";
$numero =filter_input(INPUT_POST,'numero_casa');
echo  "Numero: $numero<br>";
$result="INSERT INTO clientes (nome,telefone,bairro,rua,numero_casa) VALUES('$nome', '$telefone', '$bairro', '$rua', '$numero')";
$resultado= mysqli_query($conexao, $result);
if($result == true){
    echo "Cadastrado com Sucesso!";
}else{
    echo "Opa, Algo de errado não está certo";
}


?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.