简体   繁体   English

表格中每一行的保存按钮。 PHP MYSQL

[英]Save button for each row in the table. PHP MYSQL

Please help, each row in the table has save button for editing/adding content. 请帮忙,表格中的每一行都有保存按钮,用于编辑/添加内容。 I have 3 textboxes in each row,PersoninCharge,PIC_Comments and Status. 每行有3个文本框,PersoninCharge,PIC_Comments和Status。 The user can add/edit these textboxes whenever they click the save button on that particular row. 用户只要单击该特定行上的保存按钮,就可以添加/编辑这些文本框。 The problem is, whenever I add/edit data in one row, the save button can't read what particular row I edited. 问题是,每当我在一行中添加/编辑数据时,保存按钮都无法读取我编辑过的特定行。

The save button is perfectly running if I searched the invoice number first, but what I want is to directly edit/add the data in each row without searching it first. 如果我首先搜索发票编号,则保存按钮将完美运行,但是我想要的是直接编辑/添加每行中的数据,而无需先搜索它。

Here's the code: 这是代码:

For the table: 对于表:

<?php
if (mysqli_num_rows($result) > 0) 
{
while($row = mysqli_fetch_array($result)) 
{       
 echo"<tr class=output2>";
 echo "<td>$row[1]</td>";
 echo "<td>$row[2]</td>";
 echo "<td>$row[3]</td>";
 echo "<td>$row[4]</td>";
 echo "<td>$row[5]</td>";
 echo "<td>$row[6]</td>";
 echo "<td>$row[7]</td>";
 echo "<td>$row[8]</td>";
 echo "<td>$row[9]</td>";
 echo "<td>$row[10]</td>";
 echo "<td>$row[11]</td>";
 echo "<td>$row[12]</td>";
 echo "<td><input type='text' name='pic' value='$row[17]'></td>";
 echo "<td><input type='text' name='comt' value='$row[18]'></td>";
 echo "<td><input type='text' name='stat' value='$row[19]'></td>";
 echo "<td><form name='update' method='POST'><input type='submit' name='save_btn' value='SAVE' style='font-size:1em;'/></form></td>";
 echo "<td><input type='hidden' name='idtxt' value='$row[0]'/></td>";
 echo "</tr>"; 
 }
}
else
{
echo '<h3>No result found! </h3><br>';
}
$con->close();

For Save button: 对于保存按钮:

if(isset($_POST['save_btn']))
 {                  
 $query2="UPDATE invalid_invoice SET UpdateBy='".$_SESSION['login_user']."', UpdateDateTime=NOW(), PersoninCharge='".$_POST['pic']."', PIC_Comments='".$_POST['comt']."', Status='".$_POST['stat']."' WHERE ID='".$_POST['idtxt']."'";      
 $con->query($query2);
 $con->close();
 echo '<h3 class="datasuccess">Data successfully added!</h3>';

 }

I have edited your form. 我已经编辑了您的表格。 please have a look 请看一看

<?php
if (mysqli_num_rows($result) > 0) 
{
while($row = mysqli_fetch_array($result)) 
{       
 echo"<form name='update' method='POST'><tr class=output2>";
 echo "<td>$row[1]</td>";
 echo "<td>$row[2]</td>";
 echo "<td>$row[3]</td>";
 echo "<td>$row[4]</td>";
 echo "<td>$row[5]</td>";
 echo "<td>$row[6]</td>";
 echo "<td>$row[7]</td>";
 echo "<td>$row[8]</td>";
 echo "<td>$row[9]</td>";
 echo "<td>$row[10]</td>";
 echo "<td>$row[11]</td>";
 echo "<td>$row[12]</td>";
 echo "<td><input type='text' name='pic' value='$row[17]'></td>";
 echo "<td><input type='text' name='comt' value='$row[18]'></td>";
 echo "<td><input type='text' name='stat' value='$row[19]'></td>";
 echo "<td><input type='submit' name='save_btn' value='SAVE' style='font-size:1em;'/></td>";
 echo "<td><input type='hidden' name='idtxt' value='$row[0]'/></td>";
 echo "</tr></form>"; 
 }
}
else
{
echo '<h3>No result found! </h3><br>';
}
$con->close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM