为什么我的病情不起作用?

时间:2015-12-11 00:53:14

标签: php

为什么我的病情不起作用? Partylist不应重复。我的意思是,在图片中,学生已经在相同的位置注册了相同的位置,这是错误的  Here is the example of my provblem

我希望我的条件会出现一条错误消息,即只能注册一个部分列表

这是我的代码:

<?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'>\n";
    echo "alert('Successfully Added.');\n";
    echo "window.location = 'addcandidates.php';";
    echo "</script>";

  }
}
?>

1 个答案:

答案 0 :(得分:1)

您的条件是检查所有候选人的详细信息是否相同:
if (($count3 >= 1) AND ($count1 >= 1) AND ($numb > 1))
首先,它会检查$numb是否大于1,但您只想要一个派对的实例,因此您应该检查$numb == 1是否 但是,如果只有方是相同的,那么上述语句将不会返回true,并且用户将能够注册。 因此,您还需要声明检查 ($numb > 1)

编辑:我会包括这个声明:

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