我正在为我工作的学校建立一个 GCSE 选拔网站,但遇到了问题。
我有 6 个选择框,每个选择框有 16 个选项。
选择 6 个框后,客户单击“提交”,信息将提交到我们的 MySQL 数据库以供日后审核。
这是在我的 php 文件中完成的:
/* Attempt MySQL server connection.*/
$link = mysqli_connect("xxxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt insert query execution
$sql = "INSERT INTO xxxxxx (username, dob, form, opt1, opt2, opt3, opt4, optRes1, optRes2) VALUES ('$username', '$dob', '$form', '$opt1', '$opt2', '$opt3', '$opt4', '$optRes1', '$optRes2')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
它必须以这样的方式工作:当客户端在一个框中选择一个选项时,该选项就会在其他 5 个框中被禁用,这样用户就无法多次选择同一选项。为了实现这一点,我在 index.html 文件中使用了以下代码:
<script type="text/JavaScript" language="JavaScript">
$(function()
{
$('select').change(function(){
if($(this).attr('id') == 'opt1' && $(this).val() == 'Default'){
$('select').not(this).prop('disabled', true).val('Disabled');
} else {
$('select').not(this).removeProp('disabled');
$('select option').removeProp('disabled');
$('select').each(function(){
var val = $(this).val();
if(val != 'Default' || val != 'Disabled'){
$('select option[value="'+val+'"]').not(this).prop('disabled', true);
}
});
}
});
});
</script>
我面临的问题是,当上面的代码位于index.html文件中时,客户端单击提交,MySQL数据库仅接收$username和$dob数据。未收到 $form、$opt1、$opt2、$opt3、$opt4、$optRes1、$optRes2,并且未填充这些列。
如果我把 JavaScript 去掉,它就可以正常工作。
谁能给我一些指点。
非常感谢,
jack
最佳答案
试试这个:
$('select').not(this).prop('disabled', false);
$('选择选项').prop('禁用', false);
关于javascript - removeProp 清除 MySQL INSERT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41506734/