Javascript 使用phpl在mysql的列中输入相同值时显示警报
在同一列中输入相同值时出现问题。当输入的值与mysql中的现有记录相同时,程序应执行警报。政党和立场是两个领域。例如,当已经存在具有相同值的记录时,程序不应在同一“政党”中接受“总统” 请帮助: 以下是我编写的代码:Javascript 使用phpl在mysql的列中输入相同值时显示警报,javascript,php,mysql,Javascript,Php,Mysql,在同一列中输入相同值时出现问题。当输入的值与mysql中的现有记录相同时,程序应执行警报。政党和立场是两个领域。例如,当已经存在具有相同值的记录时,程序不应在同一“政党”中接受“总统” 请帮助: 以下是我编写的代码: if($_POST['party'] == $row['Party']){ if($_REQUEST['position'] == 'President'){ echo "<script> alert('
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');
}
}
if($\u POST['party']==$row['party'])){
如果($_请求['position']=='President'){
回声“
警惕(“党名单上已经有总统或副总统了”);
window.location.href='add_candidate.php';
";
会话_destroy();
}
如果($_请求['position']=“副总裁”){
回声“
警惕(“党名单上已经有总统或副总统了”);
window.location.href='add_candidate.php';
";
会话_destroy();
}
否则{
//ito yung nagdadagdag ng数据sa表
mysqli_查询($con,“插入tbl_候选值($idNumber’、$fname’、$mname’、$lname’、$year’、$course’、$position’、$party’、$picture’、'0');
标题('Location:list_candidate.php');
}
}
否则{
//ito yung nagdadagdag ng数据sa表
mysqli_查询($con,“插入tbl_候选值($idNumber’、$fname’、$mname’、$lname’、$year’、$course’、$position’、$party’、$picture’、'0');
标题('Location:list_candidate.php');
}
}
如何在数据库级别进行管理?使用唯一索引