後以複選框(交換機)的形式檢查複選框(交換機)的狀態,如何在提交後檢查交換機的狀態以更新MySQL?謝謝PHP如何在提交
因此,MySQL表不會改變。
從複選框,並提交
<form method="POST" action="process.php">
<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();" class="mdl-button mdl-js-button
mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="submit"
value="Salva" name="submitBtn">
</form>
開關控制和MySQL更新(process.php)
<?php
session_start();
mysql_connect(localhost) or die(mysql_error());
mysql_select_db("*******") or die(mysql_error());
$user = $_SESSION['users'];
if(isset($_POST['submitBtn'])) { //form submission occured
if(!isset($_POST['switch-1'])){
$sql = "UPDATE `*******`.`login_users` SET `auth` = \'checked\' WHERE username = '$user'";
header("location: https://*******.php");
} else {
$sql = "UPDATE `*******`.`login_users` SET `auth` = \'unchecked\' WHERE username = '$user'";
header("location: https://*******.php");
}
}
?>
你剛剛把php放入js中嗎? – deg
在頁面發送給客戶端之前,PHP在服務器上運行。它不在客戶端上運行。 –
爲什麼你把腳本標籤和PHP內? – z3nth10n