Hi there, I have a form with a checkbox on it that changes a value in a database. When its checked, the value in the db is changed to 1 and when it's unchecked, the value is 0. This is working perfectly, except that after the form is submitted, the form doesn't update (ie if you uncheck the box and hit the submit button, the form shows the box checked again). I understand why this is happening; the form is loaded and then the database value is changed, so the form only shows the initial database value.
Here is the code:
<form method="POST" name="sustForm">
<input type="checkbox" name="sustainability<?=$pid?>" VALUE=<?php echo ($p['sustainability'] == 1 ? "1 CHECKED" : "0"); ?> />Sustainability
<input type="submit" name="submit_sust<?=$pid?>" value="Save Change" onClick=<?php setSustainability($p['sustainability'], $pid, $conn); ?> />
</form>
<? function setSustainability( $psust, $pid, $conn){
if(isset($_POST['sustainability'.$pid ])){
if($psust == 0){
mysql_query(...) or die(mysql_error());
}
}else{
if ($psust == 1){
mysql_query(...) or die(mysql_error());
}
}
}
?>
I can't put a meta tag in there to refresh the page after changing the database values because the method call is the onClick...and I tried redirecting to the same page using header()...but that was completely wrong.
Any suggestions?
Thanks a lot