Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    190
    Thanks
    50
    Thanked 0 Times in 0 Posts

    PHP Query not returning records

    Hi All,

    I have this code to authenticate users on an active directory server and then query a table on my database that contains their user level. For some reason I am not getting any records returned when I run the query in my script but if I run it directly in MySQL i get back the expected record. In my troubleshooting I am getting the dreaded "mysql_fetch_array() expects parameter 1 to be resource, boolean given..".

    Here is the script:

    PHP Code:
    <?php require_once("connection.php"); ?>
    <?php
    function authenticate($user$password) {
      
    // Active Directory server
      
    $ldap_host "My-AD-Server";

      
    // Active Directory port
      
    $ldap_port 389;

      
    // connect to active directory
      
    $ldap ldap_connect($ldap_host$ldap_port);

      
    // verify user and password
      
    if($bind = @ldap_bind($ldap$user$password)) {

        
    // valid
        // check presence in groups
        
    $strUser=mysql_real_escape_string($user);
        
    $result=mysql_query("SELECT * FROM tblusers WHERE adUserName = '$strUser'") or die(mysql_error()); //added or die() for troubleshooting...

        
    if($result) {
          
    $row=mysql_fetch_array($result);
          
    $access=$row['userLevel'];
        }else{
          
    $access="visitor";
        } 

        
    // establish session variables
        
    $_SESSION['MM_Username'] = $user;
        
    $_SESSION['MM_UserGroup'] = $access;
        return 
    true;

      } else {
        
    // invalid name or password
        
    return false;
      }
    }
    ?>
    <?php mysql_close
    ($dbConnection); ?>
    I am getting "no database selected" as a mysql error but this is odd because I have used "require_once("connection.php");" in a number of other scripts with queries and never have had an issue. I am sure there is something simple I am overlooking. Can anyone help? Thanks in advance.

    Kind regards,

    Ken
    Last edited by MaDmiX; 08-19-2013 at 07:30 AM. Reason: More info...

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you need to require it inside the function


    PHP Code:
    <?php
    function authenticate($user$password) {
    require_once(
    "connection.php");
      
    // Active Directory server
      
    $ldap_host "My-AD-Server";
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    MaDmiX (08-19-2013)

  • #3
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    190
    Thanks
    50
    Thanked 0 Times in 0 Posts
    Thanks Arcticwarrio,

    I knew it was something simple.

    Ken


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •