我创建了一个单选按钮,当用户单击"is"值时,文本框将显示给用户,否则它们将保持隐藏状态。
我的问题是,当用户选择"is"时,我可以在 sql 中存储"is"值,但是当用户单击“无”值时,该值不会存储在数据库中
<script>
$(document).ready(function(){
$(function() {
$('input[name="yeshave"]').on('click', function() {
if ($(this).val() == 'yes') {
$('#textboxes').show();
} else {
$('#textboxes').hide();
}
});
});
});
</script>
没有单选按钮代码:
<table>
<tr>
<td>Do you haver passport:</td>
<td><input type="radio" name="yeshave" value="yes"> Yes</td>
<td><input type="radio" name="yeshave" value="no"> No</td>
</tr>
</table>
SQL 代码是:
if(isset($_POST['yeshave']))
{
$selectedValue=$_POST['yeshave'];
}
$query = "INSERT INTO upload (name, size, type, image,passport_no,dateofissue,dateofexpiry,placeofissue, having_passport ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$image','".$passno."','".$doi."','".$doe."','".$poi."','".$selectedValue."')";
mysqli_query($conn,$query) or die('Error, query failed');
最佳答案
设置检查其中之一。尝试使用 -
$selectedValue = isset($_POST['yeshave']) ? $_POST['yeshave'] : 'no';
关于javascript - 单选按钮值未存储在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30522109/