<?php
if(isset($_POST['save']))
{
$comment1 = $_POST['comment2'].",".date('Y-m-d');
$comment2 = $_POST['comment2'];
$id = $_POST['id'];
$query = "update enquires2 set comment1 = '$comment1', comment2 = '$comment2', s_date = '$s_datee' where id='$id'";
$result = mysqli_query($link,$query);
if($result==true)
{
echo "successfull";
}
else
{
echo "error!";
}
}
?>
<form method="post" name="myform">
<table>
<tr>
<th>comment1</th>
<th>comment2</th>
<th>Action</th>
</tr>
<?php
$sql = "select * from enquires2 ";
$result = mysqli_query($link,$sql);
while ($row = mysqli_fetch_array($result))
{
?>
<tr>
<td>
<input type='hidden' name='id' value='<?php echo $row['id']; ?>'>
</td>
<td>
<?php echo $row['comment1']; ?>
</td>
<td>
<input type='text' name='comment2' id='comment2' value=""/>
</td>
<td>
<input type ='submit' name='save' id='save' value='Save' />
</td>
</tr>
<?php
}
?>
</table>
</form>
在這段代碼我想更新與獨特的ID表enquires2。在下面的圖片中,你會看到具有保存按鈕的表格行只有一行,同樣它有多行,每行中都有保存按鈕。現在我希望當我點擊特定行的保存按鈕時,只有行數據將被更新。我該如何解決這個問題?請幫忙。
謝謝
可能重複[創建一個HTML表格,其中每個TR是FORM](http://stackoverflow.com/questions/4035966/create-a-html-table-where-each-tr-is-a-form ) – Ivar
據我所見$ s_datee是未定義的 –
它不是重複的@Ivar – Demonyowh