php - foreach loop submit button issue -


first of start writing php week , there may unnecessary lines:) i'm trying figuring out logic. went fine(thx stackoverflow). until,

in foreach loop statement put submit button, added db id after button name. put id after $_post too. problem first submit button works. when click others nothing happens.

thanks help. (btw tried other answers foreach button issues. didn't help)

if (isset($_post['arama'])) {     $ara = trim(strip_tags($_post["ara"]));     $duzelt = trim(strip_tags($_post["duzelt"]));     $id = $_session["id"];      if (!empty($ara)) {         echo '<div class="form-style-10">';         echo '<table><tr>';         echo "<th>İsim</th><th>cep telefonu</th><th>sabit telefonu</th>        </tr>";          $ara1 = '%'.$ara.'%';         $sql = $db -> query("select * rehber k_id='".$id."' , isim '%$ara%'");         $yok = $sql->rowcount();;          if ($yok != 0) {              echo "<form action=''  method='post'>";         foreach ($sql $dizi) {             $iden=$dizi[id];             echo "<tr><td><input type='text' name='isim1' value='$dizi[isim]'></td>";             echo "<td><input type='text' name='cep1' value='$dizi[cepno]'></td>";             echo "<td><input type='text' name='ev1' value='$dizi[evno]'></td>";             echo "<input type='hidden' name='id2' value='$iden'>";             echo "<td><input type='submit' name='duzelt".$iden."' value='duzelt'></td></form></tr>";         }         echo "</table>";          echo "</div>";      }else{         echo '<div class="form-style-10" style="background-color:#f04"><div class="section" style="color:#fffc00">'.$ara.' adında bir kullanıcı kayıtlı değildir.</div></div>';         header("refresh:3;rehber.php?mr=arama");     }     }     else{         echo '<div class="form-style-10" style="background-color:#f04"><div class="section" style="color:#fffc00">arama kutusu boş. lütfen aramak istediğiniz kişinin adını yazınız.</div></div>';         header("refresh:3;rehber.php?mr=arama");      } } $buton = "duzelt".$_post["id2"]; if (isset($_post[$buton]) && $_post[$buton]) {     $duz = $_post[$buton];     if (!empty($duz)) {             echo $_post["isim1"];             echo $_post["cep1"];             echo $_post["ev1"];             echo $_post["id2"];             echo $buton;              $sql1 = $db -> prepare("update rehber set isim = ?, cepno = ?, evno = ? id = ?");             $sql1 -> execute(array($_post["isim1"], $_post["cep1"], $_post["ev1"], $_post["id2"]));             echo "kayıt başarıyla tamamlanmıştır.";             header("refresh:3;rehber.php?mr=duzen");         }else{             echo "kaydedilecek veri yok";         }         } 

the real issue can see if initial form constructor appears outside of form element, whilst form element closed in foreach loop. move form constructor foreach loop. also, secondary, using id constant value in $iden constructor. resolved, seems want index, can foreach loop.

please observe:

    foreach ($sql $iden => $dizi) { // <-- $iden index         //$iden=$dizi[id]; <- no longer required         echo "<form action=''  method='post'>"; // <--form created inside loop         echo "<tr><td><input type='text' name='isim1' value='$dizi[isim]'></td>";         echo "<td><input type='text' name='cep1' value='$dizi[cepno]'></td>";         echo "<td><input type='text' name='ev1' value='$dizi[evno]'></td>";         echo "<input type='hidden' name='id2' value='$iden'>";         echo "<td><input type='submit' name='duzelt".$iden."' value='duzelt'></td></form></tr>";     } 

now have form being constructed within loop, , index being passed along.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -