Help in multiple if else.

Discussion in 'PHP' started by Talat50, Nov 29, 2010.

  1. #1
    Hello frnds i am using mutiple and conditions in if.but i am having problem.i have in adminaproval variable=0;but it doesnt chek its condition.its still goes to last if else.which has adminapproval=1;
    //////////////////////////////////////

    <?php
    include('../../includes/DB.class.php');
    $name = $_POST['txt_name'];
    $password = $_POST['txt_password'];
    //echo "$name";
    //echo "$password";
    //getch();
    //public function user_Exist($name,$pswd){
    require('Login_DAO.class.php');
    $login_dao=new LoginDAO();
    $returnarray=$login_dao -> user_Exist($name,$password);
    $i=$returnarray[0];
    $usertype=$returnarray[1];
    $adminApproval=$returnarray[2];

    echo "usertype=$usertype \t";
    echo "adminApproval=$adminApproval\t";

    if($i == 0)
    {

    $_SESSION['msg'] = "Wrong Username or &nbsp;Password";
    getch();
    header("Location:../index.php");
    }
    else if($i == 1 && $usertype == 'Admin')
    {
    session_start();
    $sessionid=session_id();
    echo "$sessionid";
    //$maxRegId = mysql_fetch_array($result);
    $_SESSION['id'] = $sessionid;
    header("Location:../../../../in-admin-panel/index.php");
    }

    else if($i == 1 && ( $adminApproval='0' && $usertype == 'Seller'))
    {
    echo "Wait For Admin Aproval";
    getch();
    }
    else if($i == 1 && ($usertype == 'Seller' && $adminApproval='1'))

    {

    session_start();
    $sessionid=session_id();
    echo "$sessionid";

    //Ine No=70
    getch();
    header("Location:../../Seller/myshop.php");

    }

    //}
    //}
    ?>



    ////////////////////////////////////////////////////////////////////
    OutPut

    usertype=Seller adminApproval=0 seshion id=6t50e31cf3em7l8np4cth47791
    Fatal error: Call to undefined function getch() in C:\wamp\www\architecturedataforebazaradminviewscreenshot\Final_EBazar\Final_EBazar\admin\classes\Login_BL.class.php on line 70
    /////////////////////////////////////////////////////////////////////////////
    its going on 4th else if.it should be in 3rd.
    Help me.
     
    Talat50, Nov 29, 2010 IP
  2. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #2
    First of all .... you do not have a function called getch() defined... that's why you get fatal error
    Second...

    After this line:
    $returnarray=$login_dao -> user_Exist($name,$password);

    add the code below:

    var_dump($returnarray);
    die;

    And place the output here
     
    drctaccess, Nov 29, 2010 IP
  3. Talat50

    Talat50 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Dear:
    Thanks For Replying.
    I want to explain you something first.i am not talking about Error.i am using getch() For Debuging.Ant it tells me where does execution Goes.
    and i have Recieved the array corctly.and i have printed it well.and it is correct.
    a am reciving in $adminaproval=0; which corect.
    But my execution still goes in 4th If condition.which is
    else if($i == 1 && ($usertype == 'Seller' && $adminApproval='1')){

    }
    i ahve $adminApproval=0.which is corectly printed above.


    i am sending code again:


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    <?php


    include('../../includes/DB.class.php');

    $name = $_POST['txt_name'];
    $password = $_POST['txt_password'];

    require('Login_DAO.class.php');
    $login_dao=new LoginDAO();

    $returnarray=$login_dao -> user_Exist($name,$password);

    $i=$returnarray[0];
    $usertype=$returnarray[1];
    $adminApproval=$returnarray[2];

    echo "usertype=$usertype \t";
    echo "adminApproval=$adminApproval\t";

    if($i == 0)
    {

    $_SESSION['msg'] = "Wrong Username or &nbsp;Password";
    getch();
    header("Location:../index.php");
    }
    else if($i == 1 && $usertype == 'Admin')
    {
    session_start();
    $sessionid=session_id();
    echo "$sessionid";
    $_SESSION['id'] = $sessionid;
    header("Location:../../../../in-admin-panel/index.php");
    }


    else if($i == 1 && ( $adminApproval='0' && $usertype == 'Seller'))
    {
    echo "Wait For Admin Aproval";
    getch();
    }
    else if($i == 1 && ($usertype == 'Seller' && $adminApproval='1'))
    {
    session_start();
    $sessionid=session_id();
    echo "$sessionid";
    $_SESSION['id'] = $sessionid;
    getch();
    header("Location:../../Seller/myshop.php");

    }


    ?>

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    printing:
    usertype=Seller, adminApproval=0 //output of variables

    Fatal error: Call to undefined function getch() in C:\wamp\www\architecturedataforebazaradminviewscreenshot\Final_EBazar\Final_EBazar\admin\classes\Login_BL.class.php on line 50

    my execution still going in that if condition in adminApproval=1;But i actually have adminApproval=0;

    i hope so now you get understating what i am having problem actually.
    Thanks
     
    Talat50, Nov 30, 2010 IP
  4. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #4
    I can't help until I see the values of the parameters in returnarray .... so again:

    After this line:
    $returnarray=$login_dao -> user_Exist($name,$password);

    add the code below:

    var_dump($returnarray);
    die;

    And place the output here
     
    drctaccess, Nov 30, 2010 IP
  5. Talat50

    Talat50 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sir i am telling values in parameters from Return array are these which i am printing above.

    usertype=Seller, adminApproval=0,i=1 //output of variables from Return Array.

    Values are correctly recieved and printed above.
    //////////////////////////////////////////////////////////////////////////////////////
    And After Using:


    $returnarray=$login_dao -> user_Exist($name,$password);

    var_dump($returnarray);
    die;

    ///////////////////////////////////////////////////////////////////
    Output is:
    array(3) { [0]=> string(1) "1" [1]=> string(6) "Seller" [2]=> string(1) "0" }

    ////////////////////////////////////////////////////////////////
    i think this is hapening.
    First Index [0]=i=1 //i value=1
    2nd Index [1]=usertype=Seller//value
    3rd Index [2] =adminapproval=0//

    so now what you say?
     
    Talat50, Nov 30, 2010 IP
  6. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #6
    According to these parameters

    array(3) { [0]=> string(1) "1" [1]=> string(6) "Seller" [2]=> string(1) "0" }

    i = 1, usertype = seller, adminapproval = 0

    so based on the parameters above script should not match any ifs... BUT

    it goes to number 4 because of this line:

    else if($i == 1 && ($usertype == 'Seller' && $adminApproval='1'))

    which means
    i == 1 => TRUE
    AND
    usertype == Seller => TRUE
    adminApproval = 1 => TRUE (it is = not ==)

    TRUE and TRUE evaluates TRUE

    so I guess

    $adminApproval='1' should be $adminApproval == 1

    you are missing a comparision ==

    I hope this helps
     
    drctaccess, Nov 30, 2010 IP
  7. Talat50

    Talat50 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks much sir.i was disturbing from Yesterday because of this careless ness.
    i didnt saw that it was an single "=";

    thanks once again
     
    Talat50, Nov 30, 2010 IP