如何检查卡针是否已使用?

时间:2018-08-19 05:28:31

标签: php mysql

我正在建立一个学生成绩门户,我希望将每个图钉钉给一位学生5次。 这是我的代码:

if (!$error) {
    $res=mysql_query("SELECT * from pin WHERE userid='$reg'");
    $row=mysql_fetch_array($res);
    $count = mysql_num_rows($res); // if regno correct it returns must be 1 row
    if( $count == 1 && $row['userid']==$reg ) {
        $pinid = $row['id'] ;
        $check_hw = $row['hw'] ;
        if ($check_hw <=4 ) {
            $res=mysql_query("UPDATE pin SET userid='$reg',status='1',hw=hw+1 WHERE pin='$pin'");

            $_SESSION['user'] = $row['userid'];
            header("Location: access.php");
        } else {
            $errMSG = "Card Limit Exceeded";
        }
    } else {
        $errMSG = "Card Used By Another user Or Limit Exceeded";
    }
}

这就是我想要做的,请帮忙

如果(用户输入密码){     从引脚=引脚的状态中选择状态         if(status =“ used”或图钉与输入的学生ID以外的其他ID绑定在一起){                 回显“已用卡并购买新的刮刮卡”                  header('Location:buypin.php');            }        其他{                   header('Location:rightplace.php');
                  将此图钉的状态设置为“已使用”,并将该图钉与学生ID绑定在一起               }

} 我确实将代码重写为

如果(!$ error){

        $res=mysql_query("SELECT id,userid,hw FROM pin WHERE userid=" . (int)$reg);
        $row=mysql_fetch_array($res);
        $count = mysql_num_rows($res); // if regno correct it returns must be 1 row

         if ($row = mysql_fetch_array($res)) {
            $pinid = $row['id'] ;
            $check_hw = $row['hw'] ;
            if ($check_hw <=4 ) {
            $res=mysql_query("UPDATE pin SET userid='$reg',status='1',hw=hw+1 WHERE pin='$pin'");


               $_SESSION['user'] = $row['userid'];
            header("Location: access.php");

            }

                 else {
            $errMSG = "Card Limit Exceeded";
        }
        } else {
            $errMSG = "Card Used By Another user ";
        }


    }

我的工作代码

if(isset($ _ POST ['btn-signup'])){

$reg = trim($_POST['reg']);
    $reg = strip_tags($reg);
    $reg = htmlspecialchars($reg);

    $pin = trim($_POST['pin']);
    $pin = strip_tags($pin);
    $pin = htmlspecialchars($pin);


$res=mysqli_query($con,"SELECT * FROM pin WHERE pin ='$pin'");
$row=mysqli_fetch_array($res);
$check_id = $row['userid'];
    // checking if the colum userid is empty 
    if ('' !== $row['userid']){    
       // if userid colum is not empty,reg no is correct and limit more than 4
       if ($row['userid']==$reg && $row['hw']<=4) {
            $errMSG = "log";

            }else {
            $errMSG = " Card Used Or  Limit Exceeded";
    }
    }else{

$errMSG = "log";


          }

}

?> 非常感谢

0 个答案:

没有答案