我有一张表,我正在提交给db。我表中的每一行都有: 1. row_id 2. first_name 3. last_name
Timer
***********来自DB **************的查询
<thead>
<tr>
<th>Row ID</th>
<th>first name</th>
<th>last name</th>
<th>email</th>
</tr>
</thead>
当我点击提交时,我运行我的if isset函数,foreach循环正在通过表正确的次数(我查看数据库并查看与我的表上相同的行数)但是它只是捕获1行值并在db中的行上复制它们。
这是我的提交代码:
$query = "SELECT * FROM basic ";
$select_all_query = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($select_all_query)){
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$email = $row['email'];
echo "<tr>";
echo "<td><input type='text' class='form-control' name='row_id[]' value='$i'></td>";
echo "<td><input type='text' class='form-control' name='first_name[]' value='$first_name'></td>";
echo "<td><input type='text' class='form-control' name='last_name[]' value='$last_name'></td>";
echo "<td><input type='text' class='form-control' name='emai[]' value='$email'></td>";
echo "</tr>";
$i++;
}
print_r显示
if(isset($_POST['submit'])){
foreach($_POST['row_id'] as $id){
$row_id = $_POST['row_id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$query = "INSERT INTO test_db(first_name, last_name) VALUES('{$first_name}', '{$last_name}')";
$result = mysqli_query($connection, $query);
if(!$result){die("QUERY FAILED " . mysqli_error($connection));}
if(!$connection){echo "NOT connected";}
}
print_r($_POST);
}
数据从不同的SQL数据库表进入表中,因此当它通过while循环运行时,我获取数据并将其移动到所需的格式。
有没有办法让提交捕获每行的值并让foreach运行提交值的那些行?