troubleshooting Question

Update from a foreach

Avatar of Ahmad Jaber
Ahmad JaberFlag for Côte d'Ivoire asked on
3 Comments1 Solution66 ViewsLast Modified:

I have a little trouble updating my table from a loop.
Here is my html, my update code and finally my print_r($ _POST);

No update is done, I need your help please.

<form method="POST" action="_editer_produit.php" id="Form" name="Form">

<button type="submit" name="Editer_Libelle" id="Editer_Libelle" >Edit</button>

<?php try{$Stat = $pdo->query("SELECT * FROM tb_produits_test ORDER BY Libelle_FR"); $i = 0; while($data = $Stat->fetch(PDO::FETCH_ASSOC)){ ?>

<input type="hidden" name="NumId_AA[<?php echo $i;?>]" id="NumId_AA_<?php echo $i;?>" value="<?php echo $data["NumId"]; ?>">

<input type="text" id="Libelle_FR_<?php echo $i;?>" name="Libelle_FR[<?php echo $i;?>]" value="<?php echo $data["Libelle_FR"]; ?>">
<input type="text" id="Libelle_AR_<?php echo $i;?>" name="Libelle_AR[<?php echo $i;?>]" value="<?php echo $data["Libelle_AR"]; ?>">

<?php $i++; }}catch(PDOException $e){echo "<div class='alert alert-danger'>".$e->getMessage()."</div>";} ?>


if(isset($_POST['Num_AA'])) {

$Num_AA = !empty($_POST['Num_AA']) ? $_POST['Num_AA'] : array();
$LIB_FR = !empty($_POST['LIB_FR']) ? $_POST['LIB_FR'] : array();
$LIB_AR = !empty($_POST['LIB_AR']) ? $_POST['LIB_AR'] : array();

$UPD = $pdo->prepare("UPDATE tb_produits_test SET Libelle_FR=:LIB_FR, Libelle_AR=:LIB_AR WHERE NumId=:Num_AA ");

foreach($LIB_FR as $key => $value){
$UPD->bindParam(":LIB_FR", 	$value);
$UPD->bindParam(":LIB_AR", 	$LIB_AR[$key]);

}catch(PDOException $e){echo "<div class='alert alert-warning'>".$e->getMessage()."</div>"; die();}

array(4) {
  string(0) ""
  array(3) {
    string(1) "1"
    string(1) "2"
    string(1) "3"
  array(3) {
    string(9) "libelle 1"
    string(9) "libelle 2"
    string(9) "libelle 3"
  array(3) {
    string(3) "aaa"
    string(3) "bbb"
    string(3) "ccc"
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros