Good night guys, this is the following, I have an application that was working until these days, today when I was adding a post in the database, my id_post that is Primary Key and Auto_increment is not being added, it returns the error that it my id_post can not be null
Here is the image of the error in the bank
hereisthetableinthedatabase
CREATETABLE'posts'('id_post'int(11)NOTNULLAUTO_INCREMENT,'id_pergunta'int(11)NOTNULL,'texto'varchar(5000)NOTNULL,'id_user'varchar(255)NOTNULL,'nome'varchar(255)NOTNULL,'data'datetimeNOTNULL,PRIMARYKEY('id_post'),KEY'fk_per_post'('id_pergunta'),CONSTRAINT'fk_per_post'FOREIGNKEY('id_pergunta')REFERENCES'pergunta'('id_per'))ENGINE=InnoDBAUTO_INCREMENT=9DEFAULTCHARSET=utf8
Herethephpfunctiontoaddtothebank
functionPostar($post){$comando=$this->prepare("INSERT INTO posts
(id_pergunta,texto,id_user,nome,,data)
VALUES (?,?,?,?,now())");
try{$comando->execute($post);
return true;
}
catch(Exception $e){
$this->Mensagem = $e->getMessage();
return false;
}
}
And here is the php code that you send to the add function in the database
$texto = $_POST["textoresposta"];
$user = $_SESSION["usuario"];
$usuario = $_SESSION["usuario.nome"];
$pergunta = $_POST["idpergunta"];
$comentarioid = $_POST["id_comentario"];
$textocomentario = $_POST["textocomentario"];
//Aqui fazemos o registro da opnião sobre a pergunta
$postDAO = new PostDAO();
if ($texto == ""){
echo "<h3>Você tem que escrever alguma coisa</h3>";
}else{
$postar = array($pergunta,$texto,$user,$usuario);
$sucesso = $postDAO->Postar($postar);
if($sucesso){
header("Location: feed.php");
exit();
}else{
header("Location: index.php?erro=". $postDAO->Mensagem);
}
}
I do not understand why the id_post column is returning null if it is an auto increment, if anyone can help me please would be great.