Error When Registering in Database

Asked

Viewed 66 times

0

I’m getting the following error when trying to insert some data into the database:

Unknown column 'F' in 'field list'

In case the column and the type Enum and can receive’M', or 'F', testing directly in the database saw that this error occurs when we pass the value without quotation marks, I believe I am passing the value incorrectly in the script.

PHP

$cpf    = $_POST['cpf'];
$idade  = $_POST['idade'];
$sexo   = $_POST['sexo'];

$cpf_novo = limpaCPF($cpf);

$sql_cadastrar_usuario = mysqli_query($conn, "insert into tb_usuario VALUES ('".$cpf."', ".$idade.", '".$sexo."')");

if($sql_cadastrar_usuario){
    $erro = "Pesquisa enviada com Sucesso!";
}else{
    $erro = "Erro ao cadastrar dados no banco de dados! - Error: ".mysqli_error($conn);
}

Table

create table tb_usuario (
cpf varchar(14) not null primary key,
idade int not null,
sexo enum ('M', 'F') not null
);
  • 1

    Give a var_dump in its variable $sexo, and see what content.

  • Perfect friend , with this I solved the problem, in my form I changed the fields, in sex I passed the age and age sex , then at the time of inserting I was trying to put age in the field sex ...I did not know this command , worth worth .

1 answer

0

Below is an attempt:

your:

$sql_cadastrar_usuario = my:sqli_query($conn, "insert into tb_usuario VALUES ('".$cpf."', ".$idade.", '".$sexo."')");

try like this:

$sql_cadastrar_usuario = mysqli_query($conn, "insert into tb_usuario VALUES ('$cpf', '$idade', '$sexo')");
  • Quiet man, then. I have tested also this way , and the error continues ...

  • I just changed, you’ve tried it like this?

  • @Joab Bispo, if you are going to enter all the fields of the table, it is not necessary to put the fields you will insert, so the first syntax and the second are correct, his problem is another.

  • I also tried without the quotes, error too ..

Browser other questions tagged

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