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
);
Give a
var_dump
in its variable$sexo
, and see what content.– Roberto de Campos
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 .
– DouglasNickson