这就是我的桌子的样子:
<table id="mytable" border="2" style= "background-color: #f9f9f9; color: #000000; margin: 0 auto;" >
<thead style= "background-color: #FFFFFF">
<tr>
<th>ID</th>
<th>Goal</th>
<th>Update</th>
</tr>
</thead>
<tbody>
<?php
if ($result = $link->query($query)) {
$num_rows = 0;
while ($row = $result->fetch_assoc()) {
$num_rows++;
echo
"<tr>
<td>{$row['id']}</td>
<td><input type='text' name='goal' id='goal' value='{$row['goal']}'></td>
<td><a onClick=\"javascript: return confirm('Are you sure you want to update the goal?');\" href='updategoal.php?id={$row['id']}&goal={$row['goal']}' class='aR'>Update goal</a></td>
</tr>";
}
/*freeresultset*/
}
?>
</tbody>
</table>
在updategoal.php这里:
<?php
include "dbase.php"; // Using database connection file here
$unsafe_goal = $_GET['goal'];
$safe_goal = (int)$unsafe_goal;
$unsafe_variable = $_GET['id'];
$safe_variable = (int)$unsafe_variable;
$sql = mysqli_query($link, "UPDATE goals SET goal = $safe_goal WHERE id = $safe_variable");
if($sql)
{
mysqli_close($link); // Close connection
header("location:".$_SERVER['HTTP_REFERER']);
exit;
}
else
{
echo "Error deleting record"; // display error message if not updated
}
?>
将鼠标悬停在 上时<a Update goal /a>,url 会显示如下内容:https://example.com/updategoal.php?id=1&goal=10,因此它不会将目标更改为我在输入文本中键入的内容,它只需添加与以前相同的目标即可。有小费吗?