nade93 Posted April 17, 2010 Share Posted April 17, 2010 Hi All I am using a single checkbox to control my audio on and off that i am using a form to process, however my fom will not process correctly. Basically, If checked i want the checkbox to save to the databased field (onoff) as 'checked' if the uncheck then click save i want to update the same database field with 'off' It seems like a relatively simple thing but cannot for the life of me get it right! can any one help pls? below is the code <? include('../lib/conn.php'); $query1 = "SELECT * FROM users_audio where userid='$userid'"; $onoff = $row['onoff']; $result = mysql_query($query1); while ($row = mysql_fetch_assoc($result)) { ?> <table> <tr class="css_sized_container"> <th><label for="css_sized_container"> <img src="../img/layout/sound.png" alt="audio icon" align="left" /></label></th> <td><form action="<? echo $PHP_SELF ; ?>" method="post" > <input type='checkbox' id="css_sized_container" name="checkbox" value="checked" <? if ($onoff=='checked'){echo "checked";} else if ($onoff==''){echo"";} ?> /> <input type="submit" name="submit" value="save" class="save" /> </form> <? } ?> <? include('../lib/conn.php'); if(isset($_POST['Submit'])&&($_POST['checkbox'])) { $ifchecked = $_REQUEST['checkbox']; mysql_query("UPDATE users_audio SET onoff='$ifchecked' WHERE userid='$userid'");} else { mysql_query("UPDATE users_audio SET onoff='off' WHERE userid='$userid'");} ?> thanks Link to comment https://forums.phpfreaks.com/topic/198864-single-checkbox-dilema/ Share on other sites More sharing options...
mrMarcus Posted April 17, 2010 Share Posted April 17, 2010 my fom will not process correctly you will need to expand on that as I haven't a clue what you're talking about. remember, the form is on your computer, not ours. you gotta be specific. also, lose the short tags. change all your <? to <?php to avoid broken scripts on php upgrades/change of servers. Link to comment https://forums.phpfreaks.com/topic/198864-single-checkbox-dilema/#findComment-1043833 Share on other sites More sharing options...
nade93 Posted April 17, 2010 Author Share Posted April 17, 2010 basically one checkbox, if it is checked want it to pass the value "checked" when submit button clicked. If not checked want to pass value "off" when save button clicked Link to comment https://forums.phpfreaks.com/topic/198864-single-checkbox-dilema/#findComment-1043837 Share on other sites More sharing options...
teamatomic Posted April 17, 2010 Share Posted April 17, 2010 if(isset($_POST['Submit'])){ $ifchecked = $_REQUEST['checkbox']; if($ifchecked != 'on'){$ifchecked='off';} mysql_query("UPDATE users_audio SET onoff='$ifchecked' WHERE userid='$userid'"); } HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/198864-single-checkbox-dilema/#findComment-1043842 Share on other sites More sharing options...
nade93 Posted April 17, 2010 Author Share Posted April 17, 2010 hi tematonic, ty for your reply, have tried this and fiddled around with it and non of them seem to work? Link to comment https://forums.phpfreaks.com/topic/198864-single-checkbox-dilema/#findComment-1043848 Share on other sites More sharing options...
nade93 Posted April 18, 2010 Author Share Posted April 18, 2010 hey guys, sorry to bump but this is still not working is there a simpler way to do this? all i want to do is save the response (checked or unchecked) and refresh the page where it will relfect this, however information is not passing though correctly Link to comment https://forums.phpfreaks.com/topic/198864-single-checkbox-dilema/#findComment-1044180 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.