2

I'm stuck on a simple PDO execute since like 1 hour. Probably simple thing but can't figure it out.

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in D:\PROJETS\site_webs\MY_WEBSITE\gestionGH\document_req.php on line 38

(38 is the "execute" line.)

Even by assigning directly values to the $variables, it still show the error


include("inc/connection.php");

$box = $_GET["box"];
$type = $_GET["type"];
$action = $_GET["action"];

$contenu = $db->quote($_GET["contenu"]);
$pro_nom = $db->quote($_GET["pro_nom"]);
$pro_num = $_GET["pro_num"];

if ($action == "creer")
{
    $type = 'e';
    $pro_nom = 'classique';
    $contenu = 'contenu';
    $pro_prix = 0;
    $pro_tva = 0;
    $actif = 'oui';
    
    /*
        $add = $db->query("INSERT INTO produit (pro_type,pro_nom,pro_texte,actif)
                                                                        VALUES ('$type',$pro_nom,$contenu,'oui')");*/

        $add = $db->prepare("INSERT INTO produit (pro_num, pro_type, pro_nom, pro_texte, pro_prix, pro_tva, actif)
                                                                                VALUES (NULL, :pro_type, :pro_nom, :pro_texte, :pro_prix, :pro_tva, :actif)");

        $add->bindParam(":pro_type", $type, PDO::PARAM_STR);
        $add->bindParam(":pro_nom", $pro_nom, PDO::PARAM_STR);
        $add->bindParam(":pro_text", $contenu, PDO::PARAM_STR);
        $add->bindParam(":pro_prix", $pro_prix, PDO::PARAM_STR);
        $add->bindParam(":pro_tva", $pro_tva, PDO::PARAM_STR);
        $add->bindParam(":actif", $actif, PDO::PARAM_STR);
        
        $add->execute();

Last, replacing everything with a direct request such as this works fine :

$add = $db->prepare("INSERT INTO produit (pro_num, pro_type, pro_nom, pro_texte, pro_prix, pro_tva, actif) VALUES (NULL, 'e', 'pro_nom', 'pro_texte', 0 , 0, 'oui')");

  • 4
    Your parameter named `:pro_texte` but you are binding using `:pro_text` – catcon Oct 27 '20 at 01:00
  • Does this answer your question? [SQLSTATE\[HY093\]: Invalid parameter number: parameter was not defined](https://stackoverflow.com/questions/10966251/sqlstatehy093-invalid-parameter-number-parameter-was-not-defined) – catcon Oct 27 '20 at 01:02
  • I knew it was a stupid stuff... couldn't see it. Merci Monsieur ! – Benoit Adam Oct 27 '20 at 01:10

0 Answers0