my form is form method="post">
input type="checkbox" name="facebook" value="yes">
Submit
So, what I want to do is:
a) If the checkbox is checked, I want to update the appropriate field with yes
b) If the checkbox is unchecked, I want to update the field with no
$_POST['chk_ans']
will return only when it is being checked,
if (isset($_POST['chk_ans']))
{
..Update Query here ..
}
Using this form:
<form method='POST'>
<input type='checkbox' name='myCheckbox' />
<input type='submit' name='submit' value='Submit' />
</form>
You could handle it this way serverside:
<?php
$mysqli = new mysqli("localhost", "myUser", "myPassword", "myDb");
if(isset($_POST['submit'])) {
$value = $_POST['myCheckbox'] ? 1 : 0;
$mysqli->query("UPDATE myTable SET myTinyInt = " . $value);
}
?>
Firstly you want to have everything ready in sql, a table that you want values to go into, and procedures you want to make for this to work, You may want to make a insert procedure and a update procedure. You then want to call the method so that your values can be added into sql.
Try this:
<?php
// You'll need a connection to db, in my example (mysql connection) this is not included.
// Check if form has been submitted.
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$field = (isset($_POST['facebook']) AND $_POST['facebook'] == 'yes') ? 'yes' : 'no';
// Your query: In this example for mysql extension
mysql_query('UPDATE my_table SET field="'.mysql_real_escape_string($field).'"');
}
?>