我的数据库出现问题并在其中设置了一些信息。我有一个复选框,当我点击它时,我希望它在我点击复选框时立即更改数据库中的值。我尝试了一些 if(isset($_POST['showToilet']){} 然后更改它。它不起作用,因为它可能必须重置页面。
我的一个朋友说这可能是一个javascript的东西。遗憾的是,我以前从未使用过 JS。
所以我的问题是:我可以通过单击复选框立即设置数据库信息吗?
您可以在下面找到我的代码:
<h2 align='center'>Toilet gegevens</h2>
<?php
$queryToilet = "SELECT * FROM toilet;";
$resultToilet = mysql_query($queryToilet);
echo "<table border ='1' align='center'>
<tr bgcolor= 'grey'>
<th>Show</th>
<th>Toilet</th>
<th>Art. nr.</th>
<th>Art. nr fab.</th>
<th>EAN nr.</th>
<th>Closet</th>
<th>Closet Afvoer</th>
<th>Bevest schrf</th>
<th>Reservoir</th>
<th>Hoekstop kr</th>
<th>Closet zitting</th>
<th>Imagenaam</th>
<th>Documentnaam</th>
<th>Edit</th>
</tr>";
while($row2 = mysql_fetch_array($resultToilet))
{
echo "<tr bgcolor ='white'>";
if($row2['Show'] == 1)
{
echo "<td><input type='checkbox' name='showToilet' value='true' checked/></td>";
}
else
{
echo "<td><input type='checkbox' name='showToilet' value='true'/></td>";
}
if(isset($_POST['showToilet']))
{
$queryChangeShow = "Update toilet SET show ='" . $_POST['Show'] . "'";
}
echo "<td>" . $row2['Toilet'] . "</td>";
echo "<td>" . $row2['Artnr'] . "</td>";
echo "<td>" . $row2['ArtNrFabrikant'] . "</td>";
echo "<td>" . $row2['EANnr'] . "</td>";
echo "<td>" . $row2['Closet'] . "</td>";
echo "<td>" . $row2['ClosetAfvoer'] . "</td>";
echo "<td>" . $row2['Bevestigingsschroef'] . "</td>";
echo "<td>" . $row2['Reservoir'] . "</td>";
echo "<td>" . $row2['Hoekstopkraan'] . "</td>";
echo "<td>" . $row2['Closetzitting'] . "</td>";
echo "<td>" . $row2['ImagePath'] ."</td>";
echo "<td>" . $row2['DocumentPath'] . "</td>";
echo "<td><a href=EditToilet.php?id=" . $row2['Artnr'] . ">edit</a></td>";
echo "</tr>";
}
echo "</table><br />";