Choix d'une catégorie

Par Meta Skill, il y a 6 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

j'essaye un formulaire d'ajout mais la catégorie me pose un problème j'ai toujours la même erreur ( Notice: Undefined index: pro_cat_id in C:\wamp\www\JARDITOU\script.php on line 35 & Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'pro_cat_id' ne peut être vide (null) in C:\wamp\www\JARDITOU\script.php on line 43 & PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'pro_cat_id' ne peut être vide (null) in C:\wamp\www\JARDITOU\script.php on line 43 );
voilà mon code avec mes requêtes.

<?php require "connexion_Bd.php"; $requete = "SELECT * FROM categories";$search = $bdd->query($requete); $row = $search->fetch(PDO::FETCH_OBJ); if ($_POST) { $sql = 'INSERT INTO produits( pro_id, pro_ref, pro_cat_id, pro_libelle, pro_description, pro_prix, pro_stock, pro_couleur, pro_bloque, pro_d_ajout) VALUES ( :pro_id, :pro_ref, :pro_cat_id, :pro_libelle, :pro_description, :pro_prix, :pro_stock, :pro_couleur, :pro_bloque, :pro_d_ajout)'; $req = $bdd->prepare($sql); $req->bindValue(':pro_id',$_POST['pro_id']); $req->bindValue(':pro_ref',$_POST['pro_ref']); $req->bindValue(':pro_cat_id',$_POST['pro_cat_id']); $req->bindValue(':pro_libelle',$_POST['pro_libelle']); $req->bindValue(':pro_description',$_POST['pro_description']); $req->bindValue(':pro_prix',$_POST['pro_prix']); $req->bindValue(':pro_stock',$_POST['pro_stock']); $req->bindValue(':pro_couleur',$_POST['pro_couleur']); $req->bindValue(':pro_bloque',$_POST['pro_bloque']); $req->bindValue(':pro_d_ajout',$_POST['pro_d_ajout']); $req->execute(); } ?>

j'aimerais un coup de mains afin de pouvoir m'en sortir et ajouter un produit en prenant en compte la catégorie.

j'ai toujours la même erreur ( Notice: Undefined index: pro_cat_id in C:\wamp\www\JARDITOU\script.php on line 35 & Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'pro_cat_id' ne peut être vide (null) in C:\wamp\www\JARDITOU\script.php on line 43 & PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'pro_cat_id' ne peut être vide (null) in C:\wamp\www\JARDITOU\script.php on line 43 )

2 réponses

Soundboy39, il y a 6 ans

Hello,

C'est simple, "Notice: Undefined index: pro_cat_id" signifie que l'entrée "pro_cat_id" n'existe pas dans "$_POST".

" Integrity constraint violation: 1048 Le champ 'pro_cat_id' ne peut être vide (null) " siginifie qu'il faut impérativement fournir une valeur pour le champ "pro_cat_id".

Du coup, les 2 erreurs sont liées... l'une étant la conséquence de l'autre ;-)

Meta Skill, il y a 6 ans

Bonsoir, je vous remercie pour réponse Soundboy39, mais au final j'avais fait une erreur toute bête dans mon formulaire pour section j'avais inclus 2 name donc impossible de récupérer mes valeurs, en tout cas merci pour votre réponse rapide.