SQL:更新php前端中的多行

SQL:更新php前端中的多行,php,mysql,database,Php,Mysql,Database,勾选复选框时,我正在尝试更新“row2”。当我一次只更新一行,但当选择多行时,所有选中的行都获得相同的值时,一切正常 我正在寻找一种向textarea标记添加id的方法,以便可以使用唯一值更新多行 我认为问题在于db.config中的$new\u price或者我在action2.php中更新数据库的方式 谢谢你的帮助或任何能为我指明正确方向的东西 Index.php: <form action="action2.php" id="bulk_action_form" method="pos

勾选复选框时,我正在尝试更新“row2”。当我一次只更新一行,但当选择多行时,所有选中的行都获得相同的值时,一切正常

我正在寻找一种向textarea标记添加id的方法,以便可以使用唯一值更新多行

我认为问题在于
db.config
中的
$new\u price
或者我在
action2.php中更新数据库的方式

谢谢你的帮助或任何能为我指明正确方向的东西

Index.php:

<form action="action2.php" id="bulk_action_form" method="post" name=
"bulk_action_form" onsubmit="return deleteConfirm();"></form>
<table class="bordered tablesorter" id="myTable">
    <thead>
        <tr>
            <th class="th-class check-box"><input id="select_all" name=
            "select_all" type="checkbox" value=""></th>
            <th class="th-class">ID</th>
            <th class="th-class">row2</th>
            <th class="th-class">row3</th>
        </tr>
    </thead><?php

                                if(mysqli_num_rows($query) > 0){

                                    while($row = mysqli_fetch_assoc($query)){

                            ?>
    <tr class="">
        <td align="center" class="checkbox-td"><input class="checkbox"
        height="30" name="checked_id[]" type="checkbox" value=
        "<?php echo $row['id']; ?>" width="30"></td>
        <td class="td-class"><?php echo $row['id']; ?></td>
        <td class="td-class reg-anote">
        <textarea class="text a-note" cols="10" id="confirmationText" name=
        "confirmationText" rows="1">
<?php echo $row['row2']; ?>
</textarea></td>
        <td class="td-class"><?php echo $row['row3']; ?></td>
    </tr><?php } }else{ ?>
    <tr>
        <td colspan="5">No records found.</td>
    </tr><?php } ?>
</table>
<form>
    <input class="btn btn-danger" name="bulk_delete_submit" type="submit"
    value="Delete"> <button name="price" type="submit">Submit</button>
</form>

身份证件
第2行
第3行
没有找到任何记录。
提交
action2.php:

<?php
session_start();
include_once('dbConfig.php');  
if(isset($_POST['bulk_delete_submit'])){
    $idArr = $_POST['checked_id'];
    foreach($idArr as $id){
        mysqli_query($conn,"DELETE FROM $TableName2 WHERE id=".$id);
    }
}  
if(isset($_POST['confirmationText'])){
    $idArr = $_POST['checked_id'];
    foreach($idArr as $id){
        mysqli_query($conn,"UPDATE $TableName2 SET Column2 WHERE id=".$id);
    }
}
?>

dbConfig.php:

<?php   
$new_price = $_POST['confirmationText'];
$TableName2 = 'Table2';
$dbHost = 'localhost';  //database host name
$dbUser = 'username';       //database username
$dbPass = 'password';           //database password
$dbName = 'databasename'; //database name
$conn = mysqli_connect($dbHost,$dbUser,$dbPass,$dbName);
if(!$conn){
    die("Database connection failed: " . mysqli_connect_error());
}
?>

您必须更改文本区域字段,如下所示-

<textarea class="text a-note" cols="10" id="confirmationText" name=
        "confirmationText[]" rows="1">
<?php
session_start();
include_once('dbConfig.php');  
if(isset($_POST['bulk_delete_submit'])){
    $idArr = $_POST['checked_id'];
    foreach($idArr as $id){
        mysqli_query($conn,"DELETE FROM $TableName2 WHERE id=".$id);
    }
}  

if(isset($_POST['confirmationText'])){
    $idArr = $_POST['checked_id'];
    foreach($idArr as $key => $id){
        mysqli_query($conn,"UPDATE $TableName2 SET Column2='".$new_price[$key]."' WHERE id=".$id);
    }
}
?>

在action2.php中进行如下必要的更改-

<textarea class="text a-note" cols="10" id="confirmationText" name=
        "confirmationText[]" rows="1">
<?php
session_start();
include_once('dbConfig.php');  
if(isset($_POST['bulk_delete_submit'])){
    $idArr = $_POST['checked_id'];
    foreach($idArr as $id){
        mysqli_query($conn,"DELETE FROM $TableName2 WHERE id=".$id);
    }
}  

if(isset($_POST['confirmationText'])){
    $idArr = $_POST['checked_id'];
    foreach($idArr as $key => $id){
        mysqli_query($conn,"UPDATE $TableName2 SET Column2='".$new_price[$key]."' WHERE id=".$id);
    }
}
?>

非常接近于只需更改脚本,进行一些小的编辑,它就可以按照我的要求工作!!谢谢