我在同一列中输入相同值时遇到问题。当输入的值与 mysql 中的现有记录相同时,程序应该执行警报。党派和职位是字段。例如。当已经存在具有相同值的记录时,程序不应接受同一“政党”中的“总统”。
请帮忙:
这是我编写的代码:
if($_POST['party'] == $row['Party']){
if($_REQUEST['position'] == 'President'){
echo "<script>
alert('There is already a President or Vice President for the Partylist');
window.location.href = 'add_candidate.php';
</script>";
session_destroy();
}
else if($_REQUEST['position'] == "Vice President") {
echo "<script>
alert('There is already a President or Vice President for the Partylist');
window.location.href = 'add_candidate.php';
</script>";
session_destroy();
}
else {
//ito yung nagdadagdag ng data sa table
mysqli_query($con,"INSERT INTO tbl_candidate VALUES('$idNumber', '$fname','$mname', '$lname', '$year', '$course', '$position', '$party', '$picture','0')");
header('Location: list_candidate.php');
}
}
else {
//ito yung nagdadagdag ng data sa table
mysqli_query($con,"INSERT INTO tbl_candidate VALUES('$idNumber', '$fname','$mname', '$lname', '$year', '$course', '$position', '$party', '$picture','0')");
header('Location: list_candidate.php');
}
}
最佳答案
在数据库级别管理这个怎么样?使用唯一索引?
关于javascript - 使用 phpl 在 mysql 的列中输入相同值时显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26253023/