Hi all, am trying to use bootstrap switch in my form. Am at a lost as to how to get the value of

name="onoffswitch"

from that field and insert it into mysql db, here is my code...

div class="onoffswitch">
    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
    <label class="onoffswitch-label" for="myonoffswitch">
        <div class="onoffswitch-inner"></div>
        <div class="onoffswitch-switch"></div>
    </label>
</div>
Member Avatar

diafol

A tester...

if(isset($_POST['onoffswitch']))
{
    echo "on";
}else{
    echo "off";
}

Thanks for your prompt reply...
but how do i get the values into this query :

$query ="INSERT INTO sre_log_remind VALUES('','$tag','$s_veration')";

mysql_query($query);

so that i can insert the values 'ON' or 'OFF' in to the db?

Member Avatar

diafol

You should save the values as a tinyint(1) - 0 or 1.

if(isset($_POST['onoffswitch']))
{
    $switch = 1;
}else{
    $switch = 0;
}

Or a one-liner...

$switch = (isset($_POST['onoffswitch'])) ? 1 : 0;

Then...

$query ="INSERT INTO sre_log_remind VALUES(NULL,'$tag',$switch)";    
commented: perfect solution +1

thanks Diafol, i will am giving it a try. Your contributions are always rich and deep. How long have you been programming...?

Member Avatar

diafol

Hmm, difficult to say - I've been 'playing' at programming for about 20 years. Only started to make it a serious hobby about 5 years ago. I'm not a professional programmer - that aspiration - unfortunately - is beyond my abilities - but I do enjoy playing.

LOL, thanks for your help man, it worked perfectly.Am working hard, so i can be of help to others, Greate Work Man...