php - Form not submitting correct value from datatable -


looks simple may overlooking here.

(document).ready(function(){              $('#data').datatable();    }

if (isset ($_post ['deleteuser']))  {    echo "<p>received form data</p>";    echo $_post['hidden'];  }  <form action="" method="post"> <table id="data">   <thead>     <tr>       <td>first name</td>       <td>delete name</td>       <td>email</td>       <td></td>     </tr>   </thead>   <tbody>       <?php        $cursor=$collection->find ();        foreach ( $cursor $document ) {       ?>       <tr>         <td class='first_name'>           <?php echo $document [ "first_name"]; ?>         </td>         <td class='last_name'>           <?php echo $document [ "last_name"]; ?>         </td>         <td class='email'>           <?php echo $document [ "email"]; ?>         </td>         <td>           <input type="hidden" name=hidden value='<?php echo $document ["first_name"]; ?>'>           <input type="submit" value="delete" name="deleteuser">         </td>       </tr>       <?php }?>   </tbody> </table> </form> 

here trying send value table php code on same page. when click on delete, sends in first name of last row.

causing form submit last row when button clicked? how can pass value of hidden tag row in delete button clicked on?

fyi : have enabled datatable table.

your form located in wrong place have 1 form users in it. try give form each user.

<table id="data">   <thead>     <tr>       <td>first name</td>       <td>delete name</td>       <td>email</td>       <td></td>     </tr>   </thead>   <tbody>       <?php        $cursor=$collection->find ();        foreach ( $cursor $document ) {       ?> <form action="" method="post">       <tr>         <td class='first_name'>           <?php echo $document [ "first_name"]; ?>         </td>         <td class='last_name'>           <?php echo $document [ "last_name"]; ?>         </td>         <td class='email'>           <?php echo $document [ "email"]; ?>         </td>         <td>           <input type="hidden" name=hidden value='<?php echo $document ["first_name"]; ?>'>           <input type="submit" value="delete" name="deleteuser">         </td>       </tr> </form>       <?php }?>   </tbody> </table> 

also note deleting user(s) first name sounds dangerous me. i'd delete id or email.

function example of current script does, have abc123.php , submit get ?a=1&a=2&a=3&a=4&a=5. won't 1, 2, 3, 4, , 5 because have same name. each iteration overwrites previous if print_r($_get); run array ( [a] => 5 ) outputted.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -