I have an html switch to toggle between on and off:
<label class="switch">
<input type="checkbox" id="togBtn" name="active" checked="checked">
<div class="slider round">
<span class="on">ON</span>
<span class="off">OFF</span>
</div>
</label>
You can check it live here: http://jsfiddle.net/tc4byzo8
It's checked by default onand it's inside a form:
<form method="post">
..
<input type="submit" name="submit" value="Submit" >
<form>
When the Submit button is clicked, I insert the data into the DB:
//Check if submit button is clicked.
if( isset($_POST['submit']) ){
//Insert the data into the DB.
$stmt = $conn->prepare( /* Insert query */ );
$stmt->execute();
}
The DB has column which values could be 1 or 0, So if the checkbox is checked, the value would be 1.
How to check if the checkbox is checked or not to insert the values 1 or 2?
I added the attribute checked="checked", So that it's checked by default, But when I switch it off, The checked attribute still there.