| Welcome to WebmasterWorld Guest from 188.8.131.52 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
How to update Db when user deselects checkbox
I've got this annoying problem, of how do you go about when a user deslects a checkbox, and then update the DB accordingly.
What I am trying to achieve is when a user selects a checkbox it places a 1 in the DB, if it deselects it then it place a 0 in the DB
if ($submit == 'Edit')
// obviously I need to write some code here so that a user a deselect the checkbox
<form method="post" action=show.php>
<input type=checkbox name=live value=1>
<input type="hidden" name=user_num value=<? echo $user_num?>>
<input type="submit" name="submit" value="Edit">
No value is passed when a checkbox is not selected. When it is selected you either get "on" (if no value is set) or the value assigned to the checkbox.
The only way to record both positive and negative input from checkboxes is to loop through the array of possible inputs and note which appear in the $_GET or $_POST array.
I suggest something like:
$box1checked = ($box1checked == "on") ? 1 : 0;
Can you explain how I would implement this in the code I've shown you?
|Paul in South Africa|
$live = 1;
$live = 0;
mysql_query("update tablename set live=$live
Thanks again Paul,
That did the trick :o)
Didn't realise it was relatively straightforward.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved