MySql table won't accept inserts, even when I use phpmyadmin to insert directly

I have this table that my whole web app is centered about, when I try to insert values into it, There are no errors, my :

 if (!$insertsql) {
        header("Location: ../AjoutArticle.php?message=Echec");
        exit();
    } else {
        header("Location: ../AjoutArticle.php?message=Good");
    }

returns a Good message, and even the code for email sending that happens right after it works, other tables have no issues with inserts, its just this one.

Here is the code I use for inserting :

    $insertsql = $conn->prepare('insert into article values(?,?,?,?,?,?,?,?,?,?,?,?,?) ');
            $insertsql->execute(array(0, $employeid, $titre, $auteur, $contenu, $source,$date,date("Y-m-d"),$theme,$urgence,$tendance,$lien,$employename));

Note : The exact same code works perfectly on Localhost

Are you using mysqli or PDO drivers?

In either case, the execute function also returns a result true or false. This result tells you whether the query was successful or not, e.g.:

$result = $insertsql->execute(...);

if ($result) {
    echo "all is good!";
} else {
    echo "database error: ".$conn->error;
}

Checking whether $insertsql is false doesn’t really do anything. It only tells you whether the statement was created correctly, not whether it executed successfully. And assuming that code is below your insertion code, the case where it would happen your code would just crash.

1 Like

Yeah but what about when I try to do an insert directly from PhpMyAdmin ? it gives no errors or anything , the execute button just doesnt do anything

Try the above code. It will help us better understand something.

OK, you conclude that it “just doesn’t do anything”. So can you please describe what do you actually see? Because phpMyAdmin should either show an error or tell you that a row has been inserted. It should never “doesn’t do anything”.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.