其他声明不工作和idk为什么

时间:2017-04-04 12:28:32

标签: php mysql login

我的其他声明,我有标题回到test.php页面是不工作的,我不知道为什么但if / true语句工作正常并将此人发送给passengerHome.php页面,当他们输入正确的凭据时

<?php
    //Feedback variable to update user of system status
        $feedback= "";
    //retrieve the details from the POST Global Variable
      $user = $_POST['username'];
        $pass = $_POST['password'];


    validate($user, $pass);
    if($feedback != ""){
      Header("Location:../presentation/passengerLogin.php?feedbackMsg=$feedback");
    }else {//check the database to see if the username and password combination matches
        //clean and format the data
            sanitize($user);
            sanitize($pass);
            //include connection string
            include("../data/dbConnection.php");

                if ($stmt = mysqli_prepare($mysqli, "SELECT  commuteType, status, passengerID FROM tblPassenger WHERE username = ? AND password = ?"))
                //bind parameters for markers
                                mysqli_stmt_bind_param($stmt, "ss", $user, $pass);
                                //execute query
                                mysqli_stmt_execute($stmt);

                                //bind value holders to result set
                                mysqli_stmt_bind_result($stmt,  $ct, $status, $passenger);
                                if (mysqli_stmt_fetch($stmt))
                    {
                        session_start();
                        $_SESSION['commuteType'] = $ct;
                        $_SESSION['status'] = $status;
                        $_SESSION['passengerID'] = $passenger;
                        if ($ct == "passenger" && $status == 1 && $passenger != "") {
                            Header("Location: ../presentation/passengerHome.php");
                        }else{
                            Header("Location: ../presentation/test.php");
                        }


                    }

    }


    //Function to SANITIZE (Clean) datax`
    function sanitize($data){
      $data = trim($data);
      $data = stripslashes($data);
      $data = filter_var($data, FILTER_SANITIZE_SPECIAL_CHARS);
      $data = filter_var($data, FILTER_SANITIZE_STRING);
      $data = filter_var($data, FILTER_SANITIZE_STRING);
      $data = filter_var($data, FILTER_SANITIZE_STRING);

      //for,at data for storage (maintain uniformity)
      $data = strtolower($data);
      $data = ucfirst($data);
    //validate($first, $last, $gen, $a, $user, $pass, $em, $add);
      //finally... return the cleaned and formatted data
      return $data;
    }//end sanitize function



      function validate($userVal, $passVal){
            global $feedback;

        if($userVal == null || $userVal == ""){
          $feedback .= "Username required<br/>";
        }else {
          $feedback .= "";
        }
        if($passVal == null || $passVal == ""){
          $feedback .= "Password required<br/>";
        }else {
          $feedback .= "";
        }
      }
     ?>

3 个答案:

答案 0 :(得分:0)

你有

$ct = "passenger"
在你的else语句中

,这不是比较。做到这一点

$ct == "passenger"

答案 1 :(得分:0)

有一个错误:

if ($ct = "passenger" && $status == 1 && $passenger != "") {

应该是 if ($ct == "passenger" && $status == 1 && $passenger != "") {

答案 2 :(得分:0)

你写过

$ ct =&#34;乘客&#34;

赋值语句如果条件,始终为真,则不执行其他块