简体   繁体   中英

getting value from delete update button on dynamic html table. php mysql

i am developing a webpage with a table that's populated dynamically when the page is loaded. i have a delete/update buttons on each row of the table, but i cant figure out how to get the value (message id) of the selected table row so i can run the delete/edit script on the correct record.

this is the code that populates the table:

while ($row=mysqli_fetch_array($run_post)){
       $post_date=$row['msg_post_date'];
       $post_title=$row['msg_title'];
       $post_id=$row['msg_id'];
       $post_list[]=$row['msg_id'];

       //table post date
       echo "<td><div class='thumbnail-mar-less'>$post_date</div></td>";

       //table title
       echo "<td><div class='thumbnail-mar-less'><a href='#'>$post_title</a></div></td>";

       //table buttons
       echo "<td>
       <form class='form-inline thumbnail-mar-less' role='form'>
         <div class='form-group'><button class='btn btn-default btn-sm'>Edit Post</button></div>
         <div class='form-group'><button name='delete'value=' ' class='btn btn-primary btn-sm'>Delete</button></div>
         </div>
        </td>";
        echo "</tr>";
} 

any suggestions on how i would assign and retrieve a value to each row???

You form has no "action", so it will submit to the "current" url automatically. If the current url is the same page as your form handling PHP then that's okay. Your form has no closing tag, so, the rest may look strange on the page.

as bobdye and Simon MᶜKenzie pointed out, you should have a field in the form that contains the $post_id value.

try something like this:

echo '
        <form class="some fancy classes" action="some_handler.php">
            <input type="hidden" value="'.$post_id.'">
            <input type="submit" value="go!">
        </form>
     ';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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