0

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:

CREATE TABLE `NewTable` (
`id`  smallint(4) NOT NULL AUTO_INCREMENT ,
`checked`  tinyint(4) NOT NULL DEFAULT 0 ,
PRIMARY KEY (`id`)
)
;

This is HTML code:

<html><head></head><body> 
<table>
</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)
</table>
</body></html>

That's it :)

Have a great day. Artem Vorobiev

Edited by artvor: n/a

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by akvlko
0

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

0

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

0

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

<?
//Form Submitted
if(isset('Submit')){
   $myValue = $_POST['myValue'];//Getting my Value from Post Array
    if($myValue == '1'){
        $myVal = 1;
    }else{
        $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">
</form>

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.