Hello, it's about a week that I'm searching for a simple script that do this:
So when value is 0 checkbox must be not checked and the opposite if value is 1...
So when I check box it must send value= 1 to my mysql DB and if it's not checked value must be 0 (Obviously when i press update button)

Please.. please .. I'm bagging you.. can some one provide me this simple script (complete with php html and sql info)

Here is simple example of what i have:

`id`  smallint(4) NOT NULL AUTO_INCREMENT ,
`checked`  tinyint(4) NOT NULL DEFAULT 0 ,

This is HTML code:

</td><td><input type="checkbox" > I don't do drugs</td></tr>
</td><td><input type="checkbox" > I'm drun </td></tr>
</td><td><input type="checkbox" > Trolololo</td></tr>   //  On load page this have to be chacked (taked value = 1 from DB)

That's it :)

Have a great day. Artem Vorobiev

Edited by artvor: n/a

6 Years
Discussion Span
Last Post by akvlko

OMg.. i posted here about 20 question in this website .. and did not get 1 answer.. This website is unless..

Edited by artvor: n/a


FIrst, you seem to be wanting someone to write whole code blocks for you. Also, this is a PHP question, not a SQL question, so I would post in the PHP forum.

As for your question, I dont know PHP that well, but I would bet you need an if statement that says:

IF checkedBox = NO then doSomehting
else doSOmethingElse


in the PHP you can access the Post data by Post Array and its key

//Form Submitted
   $myValue = $_POST['myValue'];//Getting my Value from Post Array
    if($myValue == '1'){
        $myVal = 1;
        $myVal = 0;
   //Now You can Store this $myVal from any Where

    /* Your Insert Query Goes here */

<form method="post" action="">
<input type="checkbox" name="myValue" value="1" checked>I Love Drugs<br>
<input type="checkbox" name="myValue" value="0">I don't do drugs<br>
<input type="submit" name="Submit" id="Sumbit" value="Save">

Enjoy !

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.