Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2007
    Location
    Sterling, VA
    Posts
    2

    Unanswered: Pull data from sql and validate in AD

    Hello all. I am trying to pull a value from a sql database and verify that value in AD. my problem is I don't know how to use the value in my sql query to verify in AD. The top part is the original query that validates the title in AD based off of someones email address. The SQL query at the bottom is what i would like to add to pull the email address out of the database. Just need to figure out how to make them work together.

    Original Query:

    if (!(preg_match ("/@domain.com/", $attrvalue))) {
    return "Error!: <font color=red>*Please enter a valid domain:@domain.com.</font>.";
    }

    // Connection info for AD
    $auth_user = "cn=USERNAME,CN=users,DC=resource,DC=ds,DC=domain, DC=com";
    $auth_pass = "*******";
    $ldap_server = "ldap://IPADDRESS";
    $ldap_port = "389";
    $base_dn = "dc=resource,dc=ds,dc=domain,dc=com";;

    $filter = "msrtcsip-primaryuseraddress=SIP:".$attrvalue."*";
    //$filter = "(proxyAddresses=*". $attrvalue.")";

    $ldapconn = ldap_connect($ldap_server,$ldap_port);
    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

    if($ldapconn){
    $ldapbind = ldap_bind($ldapconn,$auth_user,$auth_pass);

    if ($ldapbind) {
    $results = ldap_search($ldapconn, $base_dn, $filter);
    $number_returned = ldap_count_entries($ldapconn,$results);
    $info = ldap_get_entries($ldapconn, $results);

    for ($i=0; $i<$info["count"]; $i++) {
    $employee_level = $info[$i]["title"][0];
    if($employee_level == "Sr. Consultant" || $employee_level == "Consultant" || $employee_level == "Associate" || $employee_level == "")
    if($attrname == "CONTRACTOR_APPROVER_EMAIL")
    return "Error!: <font color=red>*Please enter a Primary Approver who is a level 4 or higher.</font>";
    else
    return "Error!: <font color=red>*Please enter a Secondary Approver who is a level 4 or higher.<font>";
    $emplid = $info[$i]["cn"][0];
    }

    if ($number_returned >= 1) {
    }else{
    return "Error!: <font color=red>*$attrvalue is not a valid email. <BR>Please enter an active, valid, employee email address.</font>";
    }

    } else {
    return "Error!:Unable to bind to server";
    //echo "LDAP bind failed...";
    }

    }else {
    return "Error!:Could not connect to ldap server";
    }


    SQL query i would like to return a certain value:

    $sql = "select avalue from MXIV_ENTRIES where mskey=$attrvalue and attrname='email'";
    $rs3 = db_query($sql);
    $row = db_fetch_row($rs3);
    return $row[0];

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I think I've found your problem:
    HTML Code:
    $sql = "select avalue from MXIV_ENTRIES where mskey = '"
    $sql = $sql . $attrvalue
    $sql = $sql . " and attrname = 'email' "
    (I think a full stop is the concatenation in php... having never coded in php I can't really be sure )
    George
    Home | Blog

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by georgev
    I think I've found your problem:
    HTML Code:
    $sql = "select avalue from MXIV_ENTRIES where mskey = '"
    $sql = $sql . $attrvalue
    $sql = $sql . " and attrname = 'email' "
    (I think a full stop is the concatenation in php... having never coded in php I can't really be sure )
    ..id check the quotes and sting comparators

    true, but I'd normally use (especailly wehen building a SQL string [for legibility purposes]).....
    $strSQL = "select avalue from MXIV_ENTRIES where mskey = '";
    $strSQL .= $attrvalue;
    $strSQL .= " and attrname = 'email' ";

    mind you you could just do the whole thin in one hit
    $strSQL = "select avalue from MXIV_ENTRIES where mskey = \"$attrvalue\" and attrname = \"email\"";
    Last edited by healdem; 04-10-07 at 05:18.
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I think it was a valiant effort considering I've never done any PHP before
    George
    Home | Blog

  5. #5
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    You haven't specified which database system you are using... and thus we do not know if your db_query/db_fetch_row function is correct.

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling, VA
    Posts
    2
    Sorry....MSSQL 2000

  7. #7
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Ok so you should be using mssql_connect, mssql_select_db, mssql_query etc...
    (http://uk2.php.net/manual/en/function.mssql-connect.php)

    Where did you get db_query from? Is this a function you have written yourself?

    Also, in your DB what datatype is the mskey?

Posting Permissions

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