从while循环使用$ _POST数据更新mysql

我想绕过我的头,但是我相当失败:[

我在一个while()循环中回显了数据库中的3行。
用户可以更改search_terms,然后将字段保存在mysql中,但是我不太知道如何执行此操作,因为有3行,所以我不能只是执行;

<?php
    if($_POST['update']) {
        mysql_query("....");
    }
?>


这是我的代码;

<?php
    $box_query = mysql_query("SELECT * FROM `ta_boxs`");
    while($box = mysql_fetch_array($box_query)) {

        echo '<div class="box_content">';
        echo '<div class="box">'."\n";
        echo '<span class="box_top"></span>';
        echo '<div class="box_header"><input type="text" id="title" name="title" class="title-input" value="'.$box['title'].'" /></div>';
        echo '<span class="sept"></span>';
        echo '<div class="admin-back">';
        echo '<form id="form-'.$box['id'].'" name="form-'.$box['id'].'" method="post" action="">';
        echo '<p class="sub"><span>Includes:</span> Search for these terms in Twitter Feeds.</p>';
        echo '<p class="sub-small">Please enter one word per field or click "add word".</p>';
        echo '<p><input type="text" id="search_term_1" name="search_term_1" value="'.$box['search_term_1'].'" class="term-input" />';
        echo '<p><input type="text" id="search_term_2" name="search_term_2" value="'.$box['search_term_2'].'" class="term-input" />';
        echo '<p><input type="text" id="search_term_3" name="search_term_3" value="'.$box['search_term_3'].'" class="term-input" />';
        echo '<span class="hr"></span>';
        echo '<p class="sub"><span>Excludes:</span> Ignore these terms in Twitter Feeds.</p>';
        echo '<p class="sub-small">Please enter one word per field or click "add word".</p>';
        echo '<p><input type="text" id="search_term_1" name="search_term_1" value="'.$box['exc_search_term_1'].'" class="term-input" />';
        echo '<p><input type="text" id="search_term_2" name="search_term_2" value="'.$box['exc_search_term_2'].'" class="term-input" />';
        echo '<p><input type="text" id="search_term_3" name="search_term_3" value="'.$box['exc_search_term_3'].'" class="term-input" />';
        echo '<input type="hidden" id="update" name="update" value="yes" />'
        echo '<p><input type="submit" id="update_'.$box['id'].'" name="update_'.$box['id'].'" value="Update" /></p>';
        echo '</form>';
        echo '</div>';
        echo '</div>'."\n";
        echo '<span class="box_bottom"></span>';
        echo '</div>';
    }
?>


可能有1个输出或100,但是我需要一种在提交时保存所有输出的方法。有任何想法吗?

最佳答案

由于要在不同的<form>中输出每个框,因此每个框都只能返回一个。
如果您更改:

<input type="hidden" id="update" name="update" value="yes" />




<input type="hidden" id="update" name="update" value="' . $box['id'] . '" />


然后,您将可以查看发回的邮件。

10-06 14:23
查看更多