dqs86517 2015-12-11 00:53
浏览 16
已采纳

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

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

  }
}
?>
  • 写回答

1条回答 默认 最新

  • du7999 2015-12-11 01:03
    关注

    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 */
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。