[RESOLU] erreur : "Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in"

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RESOLU] erreur : "Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in"

erreur : "Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in"

par iso » 16 mars 2022, 12:08

Bonjour voilà 2 jours que je suis bloqué sur cette erreur un coup de main me serais le bienvenu.

Voilà mon code :

Code : Tout sélectionner

<?php $pagetitle = "Sorties"; $pagelocation = "../"; include("../asset/include/head.php"); $req= $bdd->prepare('INSERT INTO `stockclairoix` (fournisseur, ref, stockréel, DATES, emplacement) VALUES (:nom, :ref, :stock, :dat, :emplacement)'); $requpt=$bdd->prepare('UPDATE `stockclairoix` SET stockréel= :stock, réservé= :résa WHERE `stockclairoix`.ref= :ref'); $requpt2=$bdd->prepare('UPDATE `stockclairoix` SET stockréel= :stock WHERE `stockclairoix`.ref= :ref'); $reponse= $bdd->query('SELECT * FROM `stockclairoix` ORDER BY DATES'); $donnees=$reponse->fetch(); $sup= $bdd->prepare('DELETE FROM `stockclairoix` WHERE `ref`= :ref'); $upt= $bdd->prepare('UPDATE `stockclairoix` SET fournisseur= :nom, ref= :ref, emplacement= :emplacement, DATES= :dat WHERE `stockclairoix`.ref= :ref'); $nom=""; $ref=""; $stock=""; $emplacement=""; $dat=date('d/m/Y'); $error = array(); $ierr = 0; if ($r==1){ if(isset($_POST['delref'])){ $sup->execute(array( ':ref' => $_POST['delref'] )); header('Location: ../../SC/Stock/Sortie.php'); };} ?> <script> if ( window.history.replaceState ) { window.history.replaceState( null, null, window.location.href ); } </script> <div class="card" style="width: 100%; box-shadow: 11px 12px 20px -7px rgba(0,0,0,0.21); height: 10em; margin-top: 2em;background-color:#1F90B0 ;"> <div class="card-body"> <h5 class="card-title text-light"><i class="fas fa-plus-circle"></i> Sortie</h5> <form method="post"> <div class="input-group" method="post"> <input type="text" placeholder="Référence" aria-label="Référence" class="form-control" name="Référence"> <input type="number" min="0" max="99" placeholder="Quantité" aria-label="stock" class="form-control" name="stock"> <input type="text" maxlength="25" list="Fournisseur" placeholder="Fournisseur" aria-label="Fournisseur" class="form-control" name="Fournisseur"> <datalist id="Fournisseur"> <?php $list=$bdd->query('SELECT DISTINCT fournisseur FROM `stockclairoix`'); while($fournisseur=$list->fetch()){ ?><option value="<?php echo $fournisseur["fournisseur"]?>"><?php echo $fournisseur["fournisseur"];}?></option> </datalist> <select type="text" placeholder="Emplacement" aria-label="Emplacement" class="form-control" name="Emplacement"> <option value="Clairoix">Clairoix</option> <option value="PKG">PKM</option> </select> <div class="form-check"> <input class="form-check-input" type="checkbox" value="oui" id="defaultCheck1" name="résacheck" type="submit" method="post"> <label class="form-check-label" for="defaultCheck1"> Réservé </label> </div> <div> <button name="submit" type="submit" method="post" style="background-color: #ACABAB" class="btn mr-3 text-light"><i class="fas fa-arrow-alt-circle-right"></i> Envoyer</button> </div> </div> </form> </div> </div> <?php if(isset($_POST['submit'])) { $nom= $_POST['Fournisseur']; $stock= $_POST['stock']; $ref= $_POST['Référence']; $emplacement= $_POST['Emplacement']; $_POST['submit']=1; foreach ($_POST as $key => $value){ if(!$value){ $error[$ierr]=$key; $ierr++; } } if ($ierr) { $ierr= 0; echo "<div class='card text-white bg-danger mb-3' style='max-width: 18rem;margin-top: 2em; box-shadow: 11px 12px 20px -7px rgba(0,0,0,0.21);'> <div class='card-header'>Veuillez remplir tout les champs <i class='fas fa-exclamation-triangle'></i></div><div class='card-body'><h5 class='card-title'>Liste d'erreur(s)</h5>"; foreach($error as $valErr){ echo ' <p class="card-text">champ '.$valErr.' vide <br /></p> '; $ierr++; } echo '</div></div>'; } else { $refbdd= $bdd->prepare('SELECT count(`ref`) FROM `stockclairoix` WHERE `ref`= :ref'); $refbdd->execute(array( ':ref'=>$ref )); $verif=$refbdd->fetch(); if ($verif[0] == 0) { $req->execute(array( ':nom'=> $nom, ':ref'=> $ref, ':emplacement'=> $emplacement, ':stock'=> $stock, ':dat'=> $dat, )); } if(isset($_POST['résacheck'])) { $add2= $bdd->prepare('SELECT count(`ref`),`stockréel`,`réservé` FROM `stockclairoix` WHERE `ref`= :ref'); $add2->execute(array( ':ref'=>$ref )); $addrep=$add2->fetch(); $dejadispo=$addrep['stockréel']; $dejaresa=$addrep['réservé']; $stockfinal = $dejadispo-$stock; $résafinal = $dejaresa-$stock; $requpt->execute(array( ':stock'=> $stockfinal, ':résa'=> $résafinal, ':ref'=>$ref, )); $upt->execute(array( ':nom'=> $nom, ':ref'=> $ref, ':emplacement'=> $emplacement, ':dat'=> $dat, )); } else{ $add= $bdd->prepare('SELECT count(`ref`),`stockréel` FROM `stockclairoix` WHERE `ref`= :ref'); $add->execute(array( ':ref'=>$ref )); $addrep2=$add->fetch(); $dejadispo=$addrep2['stockréel']; $stockfinal = $dejadispo-$stock; $requpt2->execute(array( ':stock'=> $stockfinal, ':ref'=>$ref )); $upt->execute(array( ':nom'=> $nom, ':ref'=> $ref, ':emplacement'=> $emplacement, ':dat'=> $dat, )); } } }; ?> <h4 class="card-title text-dark" style ='margin-top: 1.5em'><i class="fas fa-plus-circle"></i> Sorties récentes</h4> <table class="table table-bordered" style ='margin-top: 3em';> <thead> <tr > <th style="width: 12%;" scope="col">Fournisseur</th> <th style="width: 12%;" scope="col">Référence</th> <th style="width: 12%;" scope="col">Stock réel</th> <th style="width: 12%;" scope="col">Emplacement</th> <th style="width: 12%;" scope="col">Date de modification</th> <th style="width: 4%;" scope="col">Supprimer</th> </tr> </thead> <?php while($donnees=$reponse->fetch()) { ?> <tr> <td><?php echo $donnees['fournisseur']; ?></td> <td><?php echo $donnees['ref']; ?></td> <td><?php echo $donnees['stockréel']; ?></td> <td><?php echo $donnees['emplacement']; ?></td> <td><?php echo $donnees['DATES']; ?></td> <td> <form method="post"><input type="hidden" name="delref" value="<?php echo $donnees['ref']?>"> <button type="submit" class="btn mr-3 text-light" style="background-color: #FF6600;" name="Supprimer"><i class="far fa-trash-alt"></i></button> </form> </td> </tr> <?php } echo '</table>'; $reponse->closeCursor(); echo '</table>'; ?> <?php include("../asset/include/footer.php");?>
et l'erreur que l'envoie de formulaire avec la checkbox cochée me donne :
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\SC\Stock\Sortie.php:121 Stack trace: #0 C:\xampp\htdocs\SC\Stock\Sortie.php(121): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\SC\Stock\Sortie.php on line 121

merci d'avance !