3

I've searched to find a resolution to problem, but the results were too complex, or too simple.

I have a basic login box to my site. I have an LDAP server that I query, to pull in the username's information, i.e. positiontitle.

I have a table named group_id, with a column named title. I want to query the column to find a match of the user's positiontitle from LDAP, in the DB. So, the query will need to include a variable. If there is a match, the user will be directed to a certain page on my site. If no match, go somewhere else. Any suggestions?

This pulls in the info from LDAP

    function getEmpInfo(){
    <?php
    $ldap = new WIN_LDAP('DEV');
$empNum = $_REQUEST['employeeNumber'];
$empResults = @$ldap->getEmpInfo($empNum);
$results = $empResults->positiontitle;
    ?>
    }

This will query the DB for a match to direct to the correct page

    $query = "Select title FROM group_id WHERE title = '$results' ";
    $posResult = mysql_query($query);


    if ($results === $posResult){
    setcookie( md5("name"), md5($_REQUEST['enumber']), time()+3600, "/","", 0);
     header('location: /admin.php');
       } else {
     setcookie( md5("general"), md5($_REQUEST['enumber']), false, "/","", 0);
   header('Location: /general.php');
    }

I know the code above does not work, but, it will give you an idea of what I'm trying to do

1
  • Mysql_query returns a handle, not your query results. You'll need need tO use mysql_num_rows() to get the number of matched rows, and mysql_fetch_assoc() to get each row. Commented Sep 28, 2013 at 2:10

1 Answer 1

1

Post Edited!

This should work :)

$myResult = mysql_query("SELECT title FROM group_id"); //This will select ALL titles
$matchFound = false;
while ($titles = mysql_fetch_row($myResult)) //This will fetch myResult until the
//last value. It's a sort of foreach.
{ 
    if ($titles[0] == $results) //For each title grabbed, we check if it is equal to
    //the $results variable. I wrote $titles[0] because mysql_fetch_row puts every row
    //fetched in an array, where the indexes represent the columns. We selected only
    //one column, so there is only $titles[0].
        $matchFound = true;
}
if ($matchFound)
    //Here goes the code to execute if you found the match
else
    //You know it

Please note that headers must be sent BEFORE displaying any layout on the page, otherwise they will not be sent. Ensure there are no spaces/returns before your php tag because it will cause the headers to not be sent.

Example #1

//no space here
<?php
    header (something); //this will be sent
?>

Example #2

 //space
<?php
    header(something); //this won't be sent
?>

Example #3

<html>
<?php
    header(something); //this won't be sent neither
?>
Sign up to request clarification or add additional context in comments.

2 Comments

$results = $empResults->positiontitle; provides the title of the given enumber. It is not a list
So, basically, I just want to take the result of $results, which is one title, pulled from the username submitted, and make sure there is a match on the table 'group_id', column 'title', to send to the correct page after login.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.