mercredi 25 juillet 2018

Do if-else statements work differently in php?

I have a php script handles authentication for an android application that I am developing. However, the script returns the values for both the if and the else.

if ( password_verify($password, $row['password']) ) {

        $index['matriculation_number'] = $row['matriculation_number'];
        $index['first_name'] = $row['first_name'];
        $index['middle_name'] = $row['middle_name'];
        $index['last_name'] = $row['last_name'];
        $index['gender'] = $row['gender'];
        $index['level'] = $row['level'];
        $index['programme'] = $row['programme'];
        $index['department'] = $row['department'];
        $index['college'] = $row['college'];

        array_push($result['login'], $index);

        $result['success'] = "1";
        $result['message'] = "success";
        echo json_encode($result);

        mysqli_close($conn);

    } else {

        $result['success'] = "0";
        $result['message'] = "error";
        echo json_encode($result);

        mysqli_close($conn);

    }

It returns: {"login":[],"success":"0","message":"error"}

Since I am new to php, I assume the error is from me. I was wondering if the if-else work differently from other languages?

Aucun commentaire:

Enregistrer un commentaire