为什么我的病情不起作用? [关闭]

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 Here is the example of my provblem

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>";

  }
}
?>

You have a condition that checks if all the candidate details are the same:
if (($count3 >= 1) AND ($count1 >= 1) AND ($numb > 1))
Firstly, it checks if $numb is greater than 1, but you only want a single instance of a party, therefor you should be checking if $numb == 1
However if only the party is the same then the above statement will not return true, and the user will be able to register. Therefor you need to also have a statement where it checks ONLY ($numb > 1)

EDIT: I would include this statement:

if ($numb == 1) {
    /* party already taken */
}