Mates,我有这个下拉菜单,我需要在任何用户点击它时用一个单选按钮更新一个部分和数据库。我不知道如何实现它。
我的下拉列表看起来像这样
<form class="form">
<div class="switch-field">
<div class="switch-title">Make Resume Public?</div>
<input type="radio" id="switch_left" name="switch_2" value="yes" checked/>
<label for="switch_left">Yes</label>
<input type="radio" id="switch_right" name="switch_2" value="no" />
<label for="switch_right">No</label>
</div>
</form>
<?php
$switch_2 = $_POST['switch_2'];
$qry = "UPDATE resumes SET public = :public WHERE memberID = :memberID";
$stm = $db->prepare($qry);
$stm->bindParam(':public', $switch_2, PDO::PARAM_STR);
$stm->bindParam(':memberID', $uid, PDO::PARAM_STR);
$stm->execute();
?>
我需要更新此部分,无论点击哪个都应该更新数据库并保持选中状态
{{1}}
感谢您的帮助和时间。
答案 0 :(得分:1)
我假设你能够更新数据库。
以下是选择单选按钮的代码
<?php
$switch_2 = $_POST['switch_2'];
$qry = "UPDATE resumes SET public = :public WHERE memberID = :memberID";
$stm = $db->prepare($qry);
$stm->bindParam(':public', $switch_2, PDO::PARAM_STR);
$stm->bindParam(':memberID', $uid, PDO::PARAM_STR);
$stm->execute();
?>
<?php
$stmt = $db->prepare("select * from jobs where jobposterID = '".$_SESSION['memberID']."'");
$stmt->execute();
$jobs = $stmt->rowCount();
?>
<a href="<?php echo DIR; ?>my-jobs.php"><i class="fa fa-suitcase"></i> MY JOBS (<?php echo $jobs; ?>) </a>
<a href="<?php echo DIR; ?>applied-jobs.php"><i class="fa fa-check-square-o"></i> APPLIED JOBS </a>
<a href="<?php echo DIR; ?>viewed-jobs.php"><i class="fa fa-eye"></i> VIEWED JOBS </a>
<a href="<?php echo DIR; ?>logout.php"><i class="fa fa-power-off"></i> LOGOUT </a>
</div>
</div>
<form class="form" id="form_abc" action="">
<div class="switch-field">
<div class="switch-title">Make Resume Public?</div>
<!-- Here you need to get the public field from database on load -->
<input type="radio" id="switch" name="switch_2" value="yes" <?php echo ($public =='Yes') ? 'checked' : ''; ?>/>
<label for="switch_left">Yes</label>
<!-- Here you need to get the public field from database on load -->
<input type="radio" id="switch" name="switch_2" value="no" <?php echo ($public =='No') ? 'checked' : ''; ?> />
<label for="switch_right">No</label>
</div>
</form>
<Script>
$("#switch").on('click',function(){
// see is this alert comes?
alert('Its working');
$("#form_abc").submit();
});
</Script>