I can’t enter data into the database

Asked

Viewed 31 times

-2

The page loads all right , however the columns are empty in the bank

{

<?php



$servername = "localhost";
$database = "login";
$username = "root";
$passwd = "odair";

$conn = mysqli_connect($servername, $username ,$passwd , $database);

$nome = mysqli_real_escape_string($conn, $_POST["nome"]);
$sobrenome = mysqli_real_escape_string($conn, $_POST["sobrenome"]);
$nascimento = mysqli_real_escape_string($conn, $_POST["bday"]);
$genero = mysqli_real_escape_string($conn, $_POST["gender"]);



$sql = "INSERT INTO 'login'.'dados' ('nome', 'sobrenome','bday','gender') VALUES ('{$nome}', '{$sobrenome}','{$nascimento}','{$genero}'";

mysqli_query($conn , $sql);
mysqli_close($conn);





?>}
  • tries to take exactly as it is in the code and replace it with real values in a SGBD(Workbench) and see if it is entering.

  • I tried without the keys , and tried to insert real values without being the variables tbm, but without success..

  • $sql = "INSERT INTO login.dados (nome, sobrenome, bday, gender) VALUES ('Odair', 'silva', '2019-02-25', 'Male')"; That way it worked... but how can I pass the values of the variables ?

1 answer

1


 $sql = "INSERT INTO login.dados (nome, sobrenome, bday, gender) VALUES ('$nome', '$sobrenome', '$nascimento', '$genero')";
  • PERFECT... was the use of simple quotes when informing the names of the columns..

Browser other questions tagged

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