0

I have a login function, but there is one problem, before redirecting to the next page I have to check if $user_data['isikukood'] is in $tootaja_data Maybe i'm doing something wrong? It doesen't works.

PhP

db_connect();
if (isset($_POST['login']) ) {
    $kasutajanimi = $_POST['kasutajanimi'];
    $password = $_POST['pass'];

    $query = mysql_query("SELECT * FROM isik WHERE nimi='$kasutajanimi'");
    $query_tootaja = mysql_query("SELECT isikukood FROM tootaja");

    $user_data = mysql_fetch_array($query);

    $count = 0;
    $tootaja_data = array();

    while($row = mysql_fetch_assoc($query_tootaja))
    {
        $tootaja_data[$count] = $row;
        $count++;

    }

    if($user_data['parool'] == $password){

        foreach($tootaja_data as $value){
            if($user_data['isikukood'] == $value){
                header('Location: ../main.php/?view=tootaja');
            }else{
                header('Location: ../main.php/?view=klient');
            }        
        }
//        print_arr($tootaja_data);

    }else{
        header('Location: ../index.php');
    }
}

1 Answer 1

2

In you code, you are comparing an entire array to a string.

the $value in your loop looks most likely something like:

$value = array('isikukood ' => 'string');

What you should do is use in_array

if(in_array($user_data['isikukood'], $value)){ ...

or compare the exact elements:

if ($user_data['isikukood'] == $value['isikukood']){ ...
Sign up to request clarification or add additional context in comments.

1 Comment

my $tootaja_data is looking like Array ( [0] => Array([isikukood] => 39305267044) [1] => Array([isikukood] => 47563421869)) . If i'm using in_array or exact element compare in foreach cycle, then if condition is true only for last element. I don't know what to think, please help if yuo can

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.