Error saving to Mysql database

Asked

Viewed 92 times

0

I couldn’t figure out why the information doesn’t save in the database I created on Phpmyadmin.

Erro ao salvar no BD

Follow the codes below:

index.html:

Name Address Email

</body>

======================================================

cadastroUsuario.php:

<?php

    $nome = $_POST['Nome'];
    $endereco = $_POST['Endereço'];
    $email = $_POST['Email'];

    $server = 'localhost';
    $user = 'Saulllofelipe';
    $pass = 'Shika9573';
    $db = 'cvdd';

    $conn = mysqli_connect($server, $user, $pass, $db);

    if ($conn->connect_error)
            echo "Erro<br>";
    else
            echo "Conectado com sucesso<br>";

    $sql = "INSERT INTO alunos(Nome, Endereço, Email) VALUES ('$nome', '$endereco', '$email')";


    if($conn->query($sql))
            echo "Seja bem vindo $nome<br>";
    else
            echo "Erro ao salvar<br>";

?>

Someone can show me the error and how to solve?

  • 1

    Address fields are with ç? Place a semicolon at the end of the query. These may be the problems

  • Post the html tbm.

  • 1

    Instead of putting echo "Erro ao salvar<br>", place echo $conn->error;. This way you will know precisely why you have not saved.

  • Then the HTML file: <html> <meta charset="utf-8"> <body> <form method= "POST" action="creatureUsuario.php"> Name<input type="text" name="Name"> Address<input type="text" name="Address"> Email<input type="text" name="Email"> <input type="Submit" value="Send"> </form> </body> </html>

  • People show up this message, but I can’t identify the error.

1 answer

0

Try this, if it doesn’t work, at least you will know where the error comes from. Then replace echo $conn->error; by echo "Erro ao salvar<br>".

<?php

    $nome = $_POST['Nome'];
    $endereco = $_POST['Endereço'];
    $email = $_POST['Email'];

    $server = 'localhost';
    $user = 'Saulllofelipe';
    $pass = 'Shika9573';
    $db = 'cvdd';

    $conn = mysqli_connect($server, $user, $pass, $db);

    if (!$conn){
            echo "Erro<br>";


    }else{
            echo "Conectado com sucesso<br>";
    }   

    $sql = "INSERT INTO alunos(Nome, Endereço, Email) VALUES ('$nome', '$endereco', '$email')";


    if($conn->query($sql)){
            echo "Seja bem vindo $nome<br>";
    }else{
            echo $conn->error;
}
?>
  • This error message appears: Successfully connected You have an error in your SQL syntax; check the manual that corresponds to your version of the Mysql server for the correct syntax to use near ' o, Email) VALUES ('Saulo',' Carlos Alberto Sá, 50',' Aulo @ gmail ')' on line 1

Browser other questions tagged

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