php - 如何使用 PHP 中的独立文本框更新多个已检查记录

标签 php html mysql

PHP - 这是我的 PHP 代码(PHP 新手)。我正在尝试使用两个文本框中的值更新使用复选框选择的多个记录。

if (isset($_POST['submit_bulk_result']) == "Submit") {
    $test_date = $_REQUEST['test_date'];
    $user_role;
    $id = $_POST['selector'];
    echo $id;
    $N = count($id);
    echo $N;
    for ($i = 0; $i < $N; $i++) {
    $get_data       = "select * from test where test_name='$id[$i]' && test_date='$test_date' && run_type='$run_type' && test_run_name='$test_run_name' && assignee='$name'";
     $get_data1      = mysqli_query($dbcon, $get_data);
     $get_count      = mysqli_num_rows($get_data1);
     $failure_reason = $_POST['reason_failure_bulk'];
     echo $failure_reason;
     echo $action_taken;
     $action_taken = $_POST['action_taken_bulk'];
     for ($i = 1; $i <= $get_count; $i++) {
     $test_name = $_POST['test_name' . "$i"];
     $update_reason_for_test  = "update test set failure_reason='$reason_failure_bulk',action_taken='$action_taken_bulk' where assignee='$name' and test_name='$test_name' && test_status!='ok' && test_date='$test_date' && run_type='$run_type' && test_run_name='$test_run_name'";
     $update_reason_for_test1 = mysqli_query($dbcon, $update_reason_for_test);
        }
    }
}
?>

HTML - 这是我的两个文本框和复选框的 HTML。抱歉,我无法粘贴整个代码。

<form name="update_result_2" id="update_result_2" action="" method="post" style="margin: auto; text-align: center; display: block;">
<tr colspan=7 align="center">
<td colspan=3 align="center"><b>Bulk Update Reason</b></td>
<td><input type="text" name="reason_failure_bulk" value="reason_failure_bulk"></td>
<td><input type="text" name="action_taken_bulk" value="action_taken_bulk"></td>
<td colspan="2"><input type="submit" name='submit_bulk_result' id="submit_bulk_result" value="BULK SUBMIT" class="btn" style="padding: 4px 20px;background:#ffae00;background: -webkit-linear-gradient(top, #ffae00, #d67600);background: -moz-linear-gradient(top, #ffae00, #d67600);background: -o-linear-gradient(top, #ffae00, #d67600);background: linear-gradient(top, #ffae00, #d67600);border:2px outset #dad9d8;font-family:Andika, Arial, sans-serif;font-size:1.1em;letter-spacing:0.05em;text-transform:uppercase;color:#fff;
text-shadow: 0px 1px 10px #000;-webkit-border-radius: 15px;-moz-border-radius: 15px;border-radius: 15px;-webkit-box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;-moz-box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;
box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;">
</td></tr>
</form>
<td><input name="selector[]" type="checkbox" value="<?php echo $get_data2['test_name'] ?>"></td></tr>

请帮助我 - 使用复选框提取内容时没有选择任何行,并且文本框中的值也没有显示 - 这就是为什么我尝试使用上面的代码来更新没有行的原因。

最佳答案

isset 将返回 truefalse,以便根据您的条件进行调整

if (isset($_POST['submit_bulk_result']) == "Submit") {

if (isset($_POST['submit_bulk_result'])) { //which will check submit button clicked or not

此外,您的selector输入位于form元素之外,因此请将其放入form

<form name="update_result_2" id="update_result_2" action="" method="post" style="margin: auto; text-align: center; display: block;">
<tr colspan=7 align="center">
<td colspan=3 align="center"><b>Bulk Update Reason</b></td>
<td><input type="text" name="reason_failure_bulk" value="reason_failure_bulk"></td>
<td><input type="text" name="action_taken_bulk" value="action_taken_bulk"></td>
<td colspan="2"><input type="submit" name='submit_bulk_result' id="submit_bulk_result" value="BULK SUBMIT" class="btn" style="padding: 4px 20px;background:#ffae00;background: -webkit-linear-gradient(top, #ffae00, #d67600);background: -moz-linear-gradient(top, #ffae00, #d67600);background: -o-linear-gradient(top, #ffae00, #d67600);background: linear-gradient(top, #ffae00, #d67600);border:2px outset #dad9d8;font-family:Andika, Arial, sans-serif;font-size:1.1em;letter-spacing:0.05em;text-transform:uppercase;color:#fff;
text-shadow: 0px 1px 10px #000;-webkit-border-radius: 15px;-moz-border-radius: 15px;border-radius: 15px;-webkit-box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;-moz-box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;
box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;">
</td>
<td><input name="selector[]" type="checkbox" value="<?php echo $get_data2['test_name'] ?>"></td>
</tr>
</form>

关于php - 如何使用 PHP 中的独立文本框更新多个已检查记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47234770/

相关文章:

MySQL 将查询结果追加到当前记录?

php - 这是在 PHP 中构造 mysql_query 的安全方法吗

php - 在 JOIN MySQL 中选择除元素之外的所有元素

javascript - 如何将日期选择器设置为 fiddle 中的文本框?

html - 菜单在 Chrome 中显示,但在 Safari 中不显示

php - 使用单个查询更新多行

php - Symfony 找不到 "GET/logout"的路由

php - jQuery 图像 slider 问题

php - PDO:调用未定义的方法 DB::query()

javascript - 从使用 POST 发送的 AJAX 请求中检索多个输入