<small id='6Fl6x'></small><noframes id='6Fl6x'>

    1. <legend id='6Fl6x'><style id='6Fl6x'><dir id='6Fl6x'><q id='6Fl6x'></q></dir></style></legend>
    2. <tfoot id='6Fl6x'></tfoot>
        <bdo id='6Fl6x'></bdo><ul id='6Fl6x'></ul>
    3. <i id='6Fl6x'><tr id='6Fl6x'><dt id='6Fl6x'><q id='6Fl6x'><span id='6Fl6x'><b id='6Fl6x'><form id='6Fl6x'><ins id='6Fl6x'></ins><ul id='6Fl6x'></ul><sub id='6Fl6x'></sub></form><legend id='6Fl6x'></legend><bdo id='6Fl6x'><pre id='6Fl6x'><center id='6Fl6x'></center></pre></bdo></b><th id='6Fl6x'></th></span></q></dt></tr></i><div id='6Fl6x'><tfoot id='6Fl6x'></tfoot><dl id='6Fl6x'><fieldset id='6Fl6x'></fieldset></dl></div>

    4. 将删除按钮添加到 PHP 结果表

      时间:2023-10-04
      <legend id='r4gX5'><style id='r4gX5'><dir id='r4gX5'><q id='r4gX5'></q></dir></style></legend>
    5. <tfoot id='r4gX5'></tfoot>

      <i id='r4gX5'><tr id='r4gX5'><dt id='r4gX5'><q id='r4gX5'><span id='r4gX5'><b id='r4gX5'><form id='r4gX5'><ins id='r4gX5'></ins><ul id='r4gX5'></ul><sub id='r4gX5'></sub></form><legend id='r4gX5'></legend><bdo id='r4gX5'><pre id='r4gX5'><center id='r4gX5'></center></pre></bdo></b><th id='r4gX5'></th></span></q></dt></tr></i><div id='r4gX5'><tfoot id='r4gX5'></tfoot><dl id='r4gX5'><fieldset id='r4gX5'></fieldset></dl></div>
        <bdo id='r4gX5'></bdo><ul id='r4gX5'></ul>

              <tbody id='r4gX5'></tbody>

                <small id='r4gX5'></small><noframes id='r4gX5'>

              • 本文介绍了将删除按钮添加到 PHP 结果表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我已将 MySQL 表的结果输出到 HTML 表.在最后一列中,我想添加一个删除选项,它调用另一个表单并删除用户.我似乎无法让它工作.

                I have outputted the results of a MySQL table to an HTML table. In the last column, I want to add a delete option which calls another form and deletes the user. I can't seem to get it to work though.

                这是我的结果页面代码:

                This is my code for the results page:

                <?php
                
                    $contacts = mysql_query("
                        SELECT * FROM contacts ORDER BY ID ASC") or die( mysql_error() );
                
                    // If results
                    if( mysql_num_rows( $contacts ) > 0 )
                    ?>
                
                    <table id="contact-list">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Telephone</th>
                                <th>Address</th>
                  <th>Delete</th>
                            </tr>
                        </thead>
                        <tbody>
                
                        <?php while( $contact = mysql_fetch_array( $contacts ) ) : ?>
                
                
                
                            <tr>
                                <td class="contact-name"><?php echo $contact['name']; ?></td>
                                <td class="contact-email"><?php echo $contact['email']; ?></td>
                                <td class="contact-telephone"><?php echo $contact['telephone']; ?></td>
                                <td class="contact-address"><?php echo $contact['address']; ?></td>
                                <td class="contact-delete"><form action='delete.php' method="post">
                <input type="hidden" name="name" value="">
                <input type="submit" name="submit" value="Delete">
                </form></td>                
                            </tr>
                
                        <?php endwhile; ?>
                
                        </tbody>
                    </table>
                

                而且,这是我的 delete.php 脚本

                and, this is my delete.php script

                <?php
                
                //Define the query
                $query = "DELETE FROM contacts WHERE name={$_POST['name']} LIMIT 1";
                
                //sends the query to delete the entry
                mysql_query ($query);
                
                if (mysql_affected_rows() == 1) { 
                //if it updated
                ?>
                
                            <strong>Contact Has Been Deleted</strong><br /><br />
                
                <?php
                 } else { 
                //if it failed
                ?>
                
                            <strong>Deletion Failed</strong><br /><br />
                
                
                <?php
                } 
                ?>
                

                很确定我只是遗漏了一些东西,但我不知道那是什么:(

                Pretty sure I'm just missing something, but I can't figure out what that is :(

                推荐答案

                您必须在删除链接中传递变量.你必须通过 <?php echo $contact['name'];?> 隐藏字段中的名称值或在 URL

                You have to pass variable in delete link. You must have to pass <?php echo $contact['name']; ?> name value in hidden field or pass this value in URL

                替换

                <td class="contact-delete">
                      <form action='delete.php' method="post">
                      <input type="hidden" name="name" value="">
                      <input type="submit" name="submit" value="Delete">
                      </form>
                </td>
                

                随着

                <td class="contact-delete">
                    <form action='delete.php?name="<?php echo $contact['name']; ?>"' method="post">
                        <input type="hidden" name="name" value="<?php echo $contact['name']; ?>">
                        <input type="submit" name="submit" value="Delete">
                    </form>
                </td>
                

                这篇关于将删除按钮添加到 PHP 结果表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何使用数据库中的值创建 PHP 两列表? 下一篇:每第三个循环后插入 tr

                相关文章

                最新文章

                <i id='qP718'><tr id='qP718'><dt id='qP718'><q id='qP718'><span id='qP718'><b id='qP718'><form id='qP718'><ins id='qP718'></ins><ul id='qP718'></ul><sub id='qP718'></sub></form><legend id='qP718'></legend><bdo id='qP718'><pre id='qP718'><center id='qP718'></center></pre></bdo></b><th id='qP718'></th></span></q></dt></tr></i><div id='qP718'><tfoot id='qP718'></tfoot><dl id='qP718'><fieldset id='qP718'></fieldset></dl></div>
              • <tfoot id='qP718'></tfoot>

              • <small id='qP718'></small><noframes id='qP718'>

              • <legend id='qP718'><style id='qP718'><dir id='qP718'><q id='qP718'></q></dir></style></legend>

                    • <bdo id='qP718'></bdo><ul id='qP718'></ul>