wwfc_barmy_army Posted October 17, 2008 Share Posted October 17, 2008 I'm using php to display users from the LDAP and i'm trying to output their usernames, so i am using this piece of code: for ($i=0; $i < $entries["count"]; $i++) { echo $entries[$i]["sAMAccountName"][0]."<br />"; } Although this produces the following error for each user: Notice: Undefined index: sAMAccountName in C:\xampp\htdocs\test4.php on line 45 Using 'displayname' works: for ($i=0; $i < $entries["count"]; $i++) { echo $entries[$i]["displayname"][0]."<br />"; } Anyone know what is causing this and how i could solve it? Thanks. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 17, 2008 Share Posted October 17, 2008 Well, first, you should really be using a "foreach" loop, not a "for" loop (also, please use the code button for listing code): <?php foreach ($entries["count"] as $entry) { echo $entry["sAMAccountName"][0]."<br />"; } ?> Second, your error is saying that the element with key "sAMAccountName" does not exist. To check what's in your array, do this before and look at the output: <?php print_r($entries); ?> Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 17, 2008 Share Posted October 17, 2008 Sorry, I missed this part. You had $entries["count"] and it should have been count($entries). That threw me off. Should have been this: <?php foreach ($entries as $entry) { echo $entry["sAMAccountName"][0]."<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 17, 2008 Share Posted October 17, 2008 No, the original poster had it correct. LDAP returns data in a crazy format. That NOTICE means that key doesn't exist. Are you sure you spelled it correct? Remember it's case sensitive. You can debug by using the following to see the key/value pairs: print_r($entries[0]); Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted October 20, 2008 Author Share Posted October 20, 2008 No, the original poster had it correct. LDAP returns data in a crazy format. That NOTICE means that key doesn't exist. Are you sure you spelled it correct? Remember it's case sensitive. You can debug by using the following to see the key/value pairs: print_r($entries[0]); Thanks, from this i found out it was all lowercase. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.