Jump to content

single checkbox dilema


nade93

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.