Why is it my condition does not work? Partylist should not be duplicate. I mean, In the picture, student has been registered in the same partylist with the same position and that's wrong
I want that my condition will have an error message that only one partylist can be register
Here is my code:
<?php
if (isset($_POST['save'])) {
$candid = mysql_real_escape_string($_POST['candid']);
$idno = mysql_real_escape_string($_POST['idno']);
$fileName = $_FILES['image']['name'];
$partyid = mysql_real_escape_string($_POST['partyid']);
$posid =mysql_real_escape_string($_POST['posid']);
$syear= mysql_real_escape_string($_POST['syearid']);
$votes = 0;
$sql3 = mysql_query("SELECT * FROM candidates WHERE idno = '$idno' AND syearid = '$syear' ")or die(mysql_error());
$count3 = mysql_num_rows($sql3);
$sql_count1 = "SELECT * FROM candidates WHERE syearid='$syear' AND partyid = '$partyid'";
$result2 = mysql_query($sql_count1) or die(mysql_error());
$numb = mysql_num_rows($result2);
$sql1 = mysql_query("SELECT * FROM candidates,school_year where candidates.syearid = school_year.syearid AND school_year.from_year like $YearNow")or die(mysql_error());
$count1 = mysql_num_rows($sql1);
if (($count3 >= 1) AND ($count1 >= 1) AND ($numb > 1)) {
echo '<br><br><center><h2>Sorry that Candidates has already registered and cannot be duplicate</h2></center>';
}
else {
$sql = "INSERT INTO candidates (candid,image,partyid,posid,syearid,idno) VALUES ('$candid','$fileName','$partyid','$posid','$syear','$idno')";
$result = mysql_query($sql) or die(mysql_error());
echo "<script type='text/javascript'>
";
echo "alert('Successfully Added.');
";
echo "window.location = 'addcandidates.php';";
echo "</script>";
}
}
?>