if AND

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johannes

    if AND

    Hey guys,

    I'm building a login script using an active or inactive state, but
    when i check for this state it just simply skips to the incorrect
    login. It looks like the If ... AND ... part isn't working. Can
    anybody give me a hand with this problem?

    here's the code I use:

    <?php
    include("connec t.php");
    session_start() ;

    if (!empty($_POST) ){
    $query = "SELECT * FROM KLANT
    WHERE Email='".$_POST["Email"]."'
    AND Wachtwoord='".$ _POST["Wachtwoord "]." ' ";
    $result=mysql_q uery($query) or die("FOUT : " . MySQL_error());

    if ((Status=="acti ef") AND (MySQL_num_rows ($result) >0)){
    $username=$_POS T["Email"];
    $wachtwoord=$_P OST["Wachtwoord "];
    session_registe r("username") ;
    session_registe r("wachtwoord") ;
    mysql_fetch_row ($result);
    header("Locatio n: winkel.php");
    exit();
    }
    elseif ((Status=="inac tief") AND (MySQL_num_rows ($result) >0)){
    $tekst="Uw account staat momenteel op niet-actief<br>
    Neem a.u.b. contact op met de winkel";
    die($tekst);
    }else{
    $tekst="U hebt geen geldige combinatie van e-mailadres en
    wachtwoord opgegeven. Maak een keuze: <br>
    <a href=\ 'inloggen.php\' >Opnieuw inloggen</a><br>
    <a href=\ 'aanmelden.php\ '>Hier registreren</a><br>";
    die($tekst);
    }}
    ?>

  • Jerry Stuckle

    #2
    Re: if AND

    Johannes wrote:
    Hey guys,
    >
    I'm building a login script using an active or inactive state, but
    when i check for this state it just simply skips to the incorrect
    login. It looks like the If ... AND ... part isn't working. Can
    anybody give me a hand with this problem?
    >
    here's the code I use:
    >
    <?php
    include("connec t.php");
    session_start() ;
    >
    if (!empty($_POST) ){
    $query = "SELECT * FROM KLANT
    WHERE Email='".$_POST["Email"]."'
    AND Wachtwoord='".$ _POST["Wachtwoord "]." ' ";
    $result=mysql_q uery($query) or die("FOUT : " . MySQL_error());
    >
    if ((Status=="acti ef") AND (MySQL_num_rows ($result) >0)){
    $username=$_POS T["Email"];
    $wachtwoord=$_P OST["Wachtwoord "];
    session_registe r("username") ;
    session_registe r("wachtwoord") ;
    mysql_fetch_row ($result);
    header("Locatio n: winkel.php");
    exit();
    }
    elseif ((Status=="inac tief") AND (MySQL_num_rows ($result) >0)){
    $tekst="Uw account staat momenteel op niet-actief<br>
    Neem a.u.b. contact op met de winkel";
    die($tekst);
    }else{
    $tekst="U hebt geen geldige combinatie van e-mailadres en
    wachtwoord opgegeven. Maak een keuze: <br>
    <a href=\ 'inloggen.php\' >Opnieuw inloggen</a><br>
    <a href=\ 'aanmelden.php\ '>Hier registreren</a><br>";
    die($tekst);
    }}
    ?>
    >
    Where are you getting Status? Are you depending on register_global s to
    be set on? If so, this is a "very bad thing".

    Also, session_registe r is similar in that it requires register_global s
    to be on.

    Rather, you should be using the $_SESSION array.


    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Johannes

      #3
      Re: if AND

      On 20 mei, 16:35, Jerry Stuckle <jstuck...@attg lobal.netwrote:
      Johannes wrote:
      Hey guys,
      >
      I'm building a login script using an active or inactive state, but
      when i check for this state it just simply skips to the incorrect
      login. It looks like the If ... AND ... part isn't working. Can
      anybody give me a hand with this problem?
      >
      here's the code I use:
      >
      <?php
      include("connec t.php");
      session_start() ;
      >
      if (!empty($_POST) ){
      $query = "SELECT * FROM KLANT
      WHERE Email='".$_POST["Email"]."'
      AND Wachtwoord='".$ _POST["Wachtwoord "]." ' ";
      $result=mysql_q uery($query) or die("FOUT : " . MySQL_error());
      >
      if ((Status=="acti ef") AND (MySQL_num_rows ($result) >0)){
      $username=$_POS T["Email"];
      $wachtwoord=$_P OST["Wachtwoord "];
      session_registe r("username") ;
      session_registe r("wachtwoord") ;
      mysql_fetch_row ($result);
      header("Locatio n: winkel.php");
      exit();
      }
      elseif ((Status=="inac tief") AND (MySQL_num_rows ($result) >0)){
      $tekst="Uw account staat momenteel op niet-actief<br>
      Neem a.u.b. contact op met de winkel";
      die($tekst);
      }else{
      $tekst="U hebt geen geldige combinatie van e-mailadres en
      wachtwoord opgegeven. Maak een keuze: <br>
      <a href=\ 'inloggen.php\' >Opnieuw inloggen</a><br>
      <a href=\ 'aanmelden.php\ '>Hier registreren</a><br>";
      die($tekst);
      }}
      ?>
      >
      Where are you getting Status? Are you depending on register_global s to
      be set on? If so, this is a "very bad thing".
      >
      Also, session_registe r is similar in that it requires register_global s
      to be on.
      >
      Rather, you should be using the $_SESSION array.
      >
      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstuck...@attgl obal.net
      =============== ===- Tekst uit oorspronkelijk bericht niet weergeven -
      >
      - Tekst uit oorspronkelijk bericht weergeven -
      Status is a textfield in a table in a database. The connection to this
      database is made in connect.php. I changed the register_global s to
      $_SESSION, but it didn't fix the AND problem i`m afraid..

      Comment

      • Schraalhans Keukenmeester

        #4
        Re: if AND

        At Sun, 20 May 2007 07:47:36 -0700, Johannes let his monkeys type:
        On 20 mei, 16:35, Jerry Stuckle <jstuck...@attg lobal.netwrote:
        >Johannes wrote:
        Hey guys,
        >>
        I'm building a login script using an active or inactive state, but
        when i check for this state it just simply skips to the incorrect
        login. It looks like the If ... AND ... part isn't working. Can
        anybody give me a hand with this problem?
        >>
        here's the code I use:
        >>
        <?php
        include("connec t.php");
        session_start() ;
        >>
        if (!empty($_POST) ){
        $query = "SELECT * FROM KLANT
        WHERE Email='".$_POST["Email"]."'
        AND Wachtwoord='".$ _POST["Wachtwoord "]." ' ";
        $result=mysql_q uery($query) or die("FOUT : " . MySQL_error());
        >>
        if ((Status=="acti ef") AND (MySQL_num_rows ($result) >0)){
        $username=$_POS T["Email"];
        $wachtwoord=$_P OST["Wachtwoord "];
        session_registe r("username") ;
        session_registe r("wachtwoord") ;
        mysql_fetch_row ($result);
        header("Locatio n: winkel.php");
        exit();
        }
        elseif ((Status=="inac tief") AND (MySQL_num_rows ($result) >0)){
        $tekst="Uw account staat momenteel op niet-actief<br>
        Neem a.u.b. contact op met de winkel";
        die($tekst);
        }else{
        $tekst="U hebt geen geldige combinatie van e-mailadres en
        wachtwoord opgegeven. Maak een keuze: <br>
        <a href=\ 'inloggen.php\' >Opnieuw inloggen</a><br>
        <a href=\ 'aanmelden.php\ '>Hier registreren</a><br>";
        die($tekst);
        }}
        ?>
        >>
        >Where are you getting Status? Are you depending on register_global s to
        >be set on? If so, this is a "very bad thing".
        >>
        >Also, session_registe r is similar in that it requires register_global s
        >to be on.
        >>
        >Rather, you should be using the $_SESSION array.
        >>
        >
        >>
        >- Tekst uit oorspronkelijk bericht weergeven -
        >
        Status is a textfield in a table in a database. The connection to this
        database is made in connect.php. I changed the register_global s to
        $_SESSION, but it didn't fix the AND problem i`m afraid..
        So, where do you fetch the status from the db? Also in connect.php? If so:
        Do both scripts begin with session_start() ? Where is $_SESSION['status']
        assigned to $status?

        If not, (where) is it ($status) set in the script you posted?

        Sh.

        Comment

        • Jerry Stuckle

          #5
          Re: if AND

          Johannes wrote:
          On 20 mei, 16:35, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          >Johannes wrote:
          >>Hey guys,
          >>I'm building a login script using an active or inactive state, but
          >>when i check for this state it just simply skips to the incorrect
          >>login. It looks like the If ... AND ... part isn't working. Can
          >>anybody give me a hand with this problem?
          >>here's the code I use:
          >><?php
          >>include("conn ect.php");
          >>session_start ();
          >>if (!empty($_POST) ){
          >> $query = "SELECT * FROM KLANT
          >> WHERE Email='".$_POST["Email"]."'
          >> AND Wachtwoord='".$ _POST["Wachtwoord "]." ' ";
          >> $result=mysql_q uery($query) or die("FOUT : " . MySQL_error());
          >> if ((Status=="acti ef") AND (MySQL_num_rows ($result) >0)){
          >> $username=$_POS T["Email"];
          >> $wachtwoord=$_P OST["Wachtwoord "];
          >> session_registe r("username") ;
          >> session_registe r("wachtwoord") ;
          >> mysql_fetch_row ($result);
          >> header("Locatio n: winkel.php");
          >> exit();
          >> }
          >> elseif ((Status=="inac tief") AND (MySQL_num_rows ($result) >0)){
          >> $tekst="Uw account staat momenteel op niet-actief<br>
          >> Neem a.u.b. contact op met de winkel";
          >> die($tekst);
          >>}else{
          >> $tekst="U hebt geen geldige combinatie van e-mailadres en
          >>wachtwoord opgegeven. Maak een keuze: <br>
          >> <a href=\ 'inloggen.php\' >Opnieuw inloggen</a><br>
          >> <a href=\ 'aanmelden.php\ '>Hier registreren</a><br>";
          >> die($tekst);
          >>}}
          >>?>
          >Where are you getting Status? Are you depending on register_global s to
          >be set on? If so, this is a "very bad thing".
          >>
          >Also, session_registe r is similar in that it requires register_global s
          >to be on.
          >>
          >Rather, you should be using the $_SESSION array.
          >>
          >- Tekst uit oorspronkelijk bericht weergeven -
          >
          Status is a textfield in a table in a database. The connection to this
          database is made in connect.php. I changed the register_global s to
          $_SESSION, but it didn't fix the AND problem i`m afraid..
          >
          Also - I missed the first time. "Status" is not a valid PHP variable
          name.

          Add the following two lines to your page to help wit your errors:

          error_reporting (E_ALL);
          ini_set("displa y_errors", "1");


          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Rami Elomaa

            #6
            Re: if AND

            Johannes kirjoitti:
            Hey guys,
            >
            I'm building a login script using an active or inactive state, but
            when i check for this state it just simply skips to the incorrect
            login. It looks like the If ... AND ... part isn't working. Can
            anybody give me a hand with this problem?
            >
            here's the code I use:
            if ((Status=="acti ef") AND (MySQL_num_rows ($result) >0)){
            ....
            elseif ((Status=="inac tief") AND (MySQL_num_rows ($result) >0)){
            You sure that it's Status, not $Status? Or do you really have this
            somewhere in code: define('Status' , 'actief'); ??

            --
            Rami.Elomaa@gma il.com

            "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
            usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

            Comment

            • Bas Cost Budde

              #7
              Re: if AND

              Uit het bericht van Johannes:
              Hey guys,
              >
              I'm building a login script using an active or inactive state, but
              when i check for this state it just simply skips to the incorrect
              login. It looks like the If ... AND ... part isn't working. Can
              anybody give me a hand with this problem?
              Bedoel je wel AND, en niet && ?

              Er -- for the english among us: do you mean to use the AND operator,
              instead of the (to me more usual) && ?

              If you put the num_rows test outside, i.e. in a separate if(), you can
              see whether your query returns a row. Something I'd do anyway. Both
              actions may be executed only if the login was valid.

              --
              Bas Cost Budde
              Holland

              Comment

              • Bas Cost Budde

                #8
                Re: if AND

                Uit het bericht van Johannes:
                Hey guys,
                >
                I'm building a login script using an active or inactive state, but
                when i check for this state it just simply skips to the incorrect
                login. It looks like the If ... AND ... part isn't working. Can
                anybody give me a hand with this problem?
                >
                here's the code I use:
                >
                <?php
                include("connec t.php");
                session_start() ;
                >
                if (!empty($_POST) ){
                (hit Send too early, sorry about that)

                you might want to narrow this test a little further. The first branch of
                POST you're using is $_POST["Email"]; if you change this test to
                if (isset($_POST["Email"])), does that help?

                --
                that same footer. Where did we set that again?

                Comment

                • Ravi

                  #9
                  Re: if AND

                  I don't know why u r getting the status before he enters the details.
                  I suggest u to get the status in that query only and fetch db row and
                  check the status here you can get it.

                  Comment

                  Working...