Column id with primary key and auto increment is returning null MYSQL PHP

-2

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.

    
asked by anonymous 14.09.2018 / 00:39

1 answer

0

The solution is just a wrong parameter in the form, it was like this

<div id="posts">    
    <form action="post_grava.php" method="post" id="publicar">
        <input type="hidden" name="idpergunta" value="<?=$pergunta["id_per"];?>"/>
        <textarea class='autoExpand' rows="1" data-min-rows='1' placeholder="O que você pensa sobre isso?" id="textoresposta" name="textocomentario"
            <?php     if(!isset($_SESSION["usuario"]) || !isset($_SESSION["usuario.nome"])) 
            { ?>
            onclick="$('#login').fadeIn(); $('#publicar').hide();" <?php } ?>></textarea> 

          <?php if(isset($_SESSION["usuario"]) || isset($_SESSION["usuario.nome"])) {?>
            <input type="submit" id="submit" value="Publicar"/>
         <?php } ?>

    </form>         
</div>

no name of form is name="textocomentario" and the correct one is name="textoresposta". problem run

    
14.09.2018 / 03:19