If condition doesn't work with ODBC

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newladder
    New Member
    • Jan 2007
    • 15

    If condition doesn't work with ODBC

    [PHP]<?
    include ("dbconn.php ");
    $userid = $_POST['userid'];
    $password = $_POST['password'];
    $select = "SELECT * FROM plus_signup WHERE userid='$userid ' AND password = '$password'";
    echo "Select : $select"; //I get the above Qurey executed here....

    $result = odbc_exec($conn ,$select);

    if($rec=odbc_fe tch_array($resu lt))//records found....Check if userid and password matches.
    {
    echo "output something...!";// this value gets printed.

    //After this, there is no exection at all...........


    if(($rec['userid']==$userid)&&($r ec['password']==$password))
    {
    $deptid = $rec['deptid'];
    echo "deptid".$depti d;
    exit();
    include "include/newsession.php" ;
    echo "<p class=data> <center>Success fully,Logged in<br><br><a href='logout.ph p'> Log OUT </a><br><br><a href=welcome.ph p>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
    print "<script>";
    print " self.location=' welcome.php';"; // Comment this line if you don't want to redirect
    print "</script>";
    }
    }

    else {
    session_unset() ;
    echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Userid and Password and Try <br><center><in put type='button' value='Retry' onClick='histor y.go(-1)'></center>";
    }

    //include ("footer.php ");
    ?>[/PHP]

    Iam using 2 if conditions in php MSSQL and i get no result for the second if...Any idea?
    You can see my comments of what is the output i get.

    Thanks....
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    What makes you think that the second if condition is definitely true? Meaning that, when it is NOT true, your script ends without any further processing.

    In order to get nearer to the problem, display an error or something in the else branch, then you know at least that your script continues. Like this

    [php] if(($rec['userid']==$userid)&&($r ec['password']==$password))
    {
    $deptid = $rec['deptid'];
    echo "deptid".$depti d;
    exit();
    include "include/newsession.php" ;
    echo "<p class=data> <center>Success fully,Logged in<br><br><a href='logout.ph p'> Log OUT </a><br><br><a href=welcome.ph p>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
    print "<script>";
    print " self.location=' welcome.php';"; // Comment this line if you don't want to redirect
    print "</script>";
    }
    else {
    print "Record does not match!";
    }
    }
    [/php]

    Ronald :cool:

    Comment

    • newladder
      New Member
      • Jan 2007
      • 15

      #3
      Hi Ronald,
      I have tried with your code but still it is the same...
      Anyway i have jsut tried one simple code mentioned below but no result.
      [PHP]<?
      $conn = odbc_connect('B illing-1','Admin','y6N DQK8fy^io@ou');
      $userid = $_POST['userid'];
      $password = $_POST['password'];
      $select = "SELECT * FROM plus_signup WHERE userid='$userid ' AND password = '$password'";
      echo "Select : $select";
      $result = odbc_exec($conn , $select);
      while ($row = odbc_fetch_arra y($result))
      {
      $rowid = $row['userid'];
      $pwd = $row['password'];
      }
      echo "Row id :".$rowid;
      echo "password : ".$pwd;
      ?>[/PHP]
      i get this result
      Select : SELECT * FROM plus_signup WHERE userid='imran' AND password = 'khan'
      Row id :
      password :

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        But you must always test the result of a query, such as:

        [php]$result = odbc_exec($conn , $select);
        if ($result) {
        $no=odbc_num_ro ws($result);
        if ($no > 0) {
        while ($row = odbc_fetch_arra y($result)) {
        $rowid = $row['userid'];
        $pwd = $row['password'];
        }
        echo "Row id :".$rowid;
        echo "password : ".$pwd;
        }
        else {
        echo 'No results in query";
        }
        }
        else
        echo "Query error!";
        ?>[/php]

        If this doesn't work, there is still another (bit far-fetched) reason could be that you do not have the correct driver installed.

        Ronald :cool:

        Comment

        • newladder
          New Member
          • Jan 2007
          • 15

          #5
          I have the drivers properly installed>
          when i Just tried with only one condition in where statement it works.
          i.e.
          [PHP]<?
          $conn = odbc_connect('s erver-1','user','pass word');
          $userid = $_POST['userid'];
          $password = $_POST['password'];
          //echo $userid;
          //echo $password;
          $select = "SELECT * FROM plus_signup where userid = '$userid' ";
          echo "Select : $select";
          $result = odbc_exec($conn , $select);
          while ($row = odbc_fetch_arra y($result))
          {
          //write out all the rows from the table
          echo "<br>".$row['userid'];
          echo "<br>".$row['password'] . '<br/>';
          }
          ?> [/PHP]
          I get the below output
          [PHP]Select : SELECT * FROM plus_signup where userid = 'tester'
          tester
          testing
          [/PHP]

          Please suggest if my query is wrong

          Comment

          • newladder
            New Member
            • Jan 2007
            • 15

            #6
            Hi Guys,

            Finally I could able to get connected and retrive records.. Its working now.
            Thanks for the precious help.

            Comment

            Working...