Monday, 9 September 2013

Checkbox changing database right away

Checkbox changing database right away

I got a problem with my Database and setting some info in it. I got a
checkbox and when I click on it, I want it to change the value right away
in the database when I click on the checkbox. I tried something with
if(isset($_POST['showToilet']){} and then change it. It doesn't work
because it probably has to reset the page.
A friend of mine said it's probably a javascript thing. Sadly I never
worked with JS before.
So my question is: Can I set database info right away by just clicking on
a checkbox?
Below you can find my code:
<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 />";

No comments:

Post a Comment