简体   繁体   English

用php生成的不同形式的提交按钮数组

[英]array of submit buttons in different forms generated with php

I dynamically create html forms with a loop in php and each submit button is assigned a name as part of an array. 我动态创建带有php循环的html表单,并且为每个提交按钮分配了一个名称,作为数组的一部分。 How can I check which submit button is set and get its value? 如何检查设置了哪个提交按钮并获取其值? I tried this code but it doesn't work. 我试过了这段代码,但是没有用。

<?php
      if($count_eksp){for($i=0; $i<$count_eksp; $i++){
      $fusha_eksp = mysql_fetch_row($query1);

      echo "<br>$fusha_eksp[2] $fusha_eksp[3]<form method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'><input name='eksp_edit[]' type='submit' value='$fusha_eksp[0]' height='20' width='20' ><input id='eksp_fshi[]' type='image' src='fshi.png' height='20' width='20'></form>";

     }}
  ?>
 <?php 
       if(isset($_POST['eksp_edit[]'])){

       foreach($_POST['eksp_edit'] as $id){
       $query = mysql_query("DELETE FROM `fusha_ekspertizes` WHERE `id`='$id'", $db_server);
       }


 }
?>

You have error in if condition, in the key. 您在密钥中的if条件中有错误。 Remove [] for that. 为此,删除[]

if (isset($_POST['eksp_edit'])) {
    ...  
}

The second error is in action attribute, you can have another <? 第二个错误是在action属性中,您可以有另一个<? inside echo . 内部echo When the form is processed on the same page, you can leave this attribute. 在同一页面上处理表单时,可以保留此属性。

echo "[...]<form method='post'><input [...]";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM