in a form i put in a checkbox (switch), how do i post after submitting to checking the status of the switch for MySQL update? thank you
Consequently the MySQL table does not change.
From checkbox and submit
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-1">
<input type="checkbox" id="switch-1" class="mdl-switch__input" checked>
<span class="mdl-switch__label">Autenticazione a due fattori</span>
</label>
....
<input onclick="conferma(); update_switch()" class="mdl-button mdl-js-button
mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="submit"
value="Salva">
</form>
Switch control and MySQL update
<script>
function update_switch() {
<?php
session_start();
mysql_connect(localhost) or die(mysql_error());
mysql_select_db("*******") or die(mysql_error());
$user = $_SESSION['users'];
if(!isset($_POST['switch-1'])){
$sql = "UPDATE `********`.`login_users` SET `auth` = \'checked\'
WHERE username = '$user'";
} else {
$sql = "UPDATE `*******`.`login_users` SET `auth` = \'no\' WHERE
username = '$user'";
}
?>
}
update_switch();
</script>
Aucun commentaire:
Enregistrer un commentaire