Jump to content

pakenney38

Members
  • Posts

    90
  • Joined

  • Last visited

    Never

Everything posted by pakenney38

  1. Apparently I got some incorrect documentation. The command I am supposed to be using is ldap_add(), not ldap_mod_add().
  2. Subsequently, if I try to run this: <?PHP $ldaprdn = 'user@test.local'; $ldappass = 'password'; $ds = 'server.test.local'; $dn = 'dc=test,dc=local'; $ldapport = 389; $ldapconn = ldap_connect($ds, $ldapport) or die("Could not connect to LDAP server."); if ($ldapconn) { ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3); ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0); $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass); if ($ldapbind) { echo "LDAP bind successful..."; $attr["cn"] = "ROSE TWILL"; $attr["objectClass"] = "contact"; $attr["sn"] = "TWILL"; $attr["givenName"] = "ROSE"; $attr["displayName"] = "ROSE TWILL (2nd Server)"; $attr["mailNickname"] = "RTWILL"; $attr["targetAddress"] = "smtp:RTWILL@domain.com"; $attr["mail"] = "RTWILL@domain.com"; $attr["proxyAddresses"] = "smtp:RTWILL@domain.net"; $result = ldap_mod_add($ldapconn, "ou=Mail Enable,ou=Test Users,ou=Test,dc=test,dc=local", $attr); } else { echo "LDAP bind failed..."; } } ldap_close($ldapconn); ?> I get back: LDAP bind successful... Warning: ldap_mod_add() [function:ldap-mod-add]: Modify: Server is unwilling to perform in C:\Intepub\wwwroot\newcontact.php on line 29 What so now Active Directory is just telling me "no" ?
  3. I am trying to use PHP to insert a contact into Windows Server 2003 Active Directory. I do this: <?PHP $ldaprdn = 'user@test.local'; $ldappass = 'password'; $ds = 'server.test.local'; $dn = 'dc=test,dc=local'; $ldapport = 389; $ldapconn = ldap_connect($ds, $ldapport) or die("Could not connect to LDAP server."); if ($ldapconn) { ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3); ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0); $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass); if ($ldapbind) { echo "LDAP bind successful..."; $attr["cn"][0] = "ROSE TWILL"; $attr["objectclass"][0] = "top"; $attr["objectclass"][1] = "person"; $attr["objectclass"][2] = "organizationalPerson"; $attr["objectClass"][3] = "contact"; $attr["sn"][0] = "TWILL"; $attr["givenName"][0] = "ROSE"; $attr["displayName"][0] = "ROSE TWILL (2nd Server)"; $attr["mailNickname"][0] = "RTWILL"; $attr["targetAddress"][0] = "smtp:RTWILL@domain.com"; $attr["mail"][0] = "RTWILL@domain.com"; $attr["proxyAddresses"][0] = "smtp:RTWILL@domain.net"; $result = ldap_mod_add($ldapconn, "ou=Mail Enable,ou=Test Users,ou=Test,dc=test,dc=local", $attr); } else { echo "LDAP bind failed..."; } } ldap_close($ldapconn); ?> I get this: LDAP bind successful... Warning: ldap_mod_add() [function.ldap-mod-add]: Value array must have consecutive indices 0, 1, ... in C:\Inetpub\wwwroot\newcontact.php on line 32 What does this mean and what am I doing wrong? I appreciate any help on this.
  4. That's kind of what I was asking. Can CONCAT be used in the WHERE clause instead of at the beginning of the SELECT statement?
  5. There is a table named tablename. And in tablename there are 3 columns: col1, col2, col3. I want to SELECT * FROM tablename WHERE col1 is equal to the concatenation of col2 and col3.
  6. Thanks. That will work. I had done that once before and forgot I could do it that way.
  7. Assume that the first numerical index of a given array is 0. Is there any way to find the highest numerical index of the array? I want to avoid using something like, if I can: $highest_index = count($array) - 1;
  8. Good point. Sorry for the confusion. Thanks for the solution.
  9. Thanks! That gets me a lot closer. Is there any way I could check to see if $str[2] equals any value within an array? Say I have: $suffixes = array('JR', 'SR', 'I', 'II', 'III', 'IV'); I realize I would have to find the number of elements in $str, but can I just do: $str = 'JOHN DOE JR'; $tmp = explode(' ',$str); if $str[2] == $suffixes { array_pop($tmp); $new_str = implode(' ',$tmp); } Sorry I don't mean to be a complete noob, but how would I work the if statement?
  10. I tried that and unfortunately there are several names in the list that are multiple words with words beginning with " I", so that will not work.
  11. Say I have a string like "JOHN DOE JR". Does anyone know the best way to truncate suffixes like " JR" from the name? I need to be able to truncate " JR", " SR", " I", " II", " III", " IV", etc on a large list of names. The names are stored in MySQL if it matters.
  12. Thanks, but that's the way it was originally and it produced the same effect.
  13. I really don't know how to explain this, but I have a Tab-delimited file that I want to read line-by-line. In a line is an employee number. I want to get the lastname and firstname of the employee from a MySQL table using the employee number as the relative key. I want to do this for each line then display the results on the screen. The problem is that the script gets the firstname and lastname of the employees until it hits an employee that is not in the MySQL table, then it fails to get the firstname and lastname for the remainder of the employees, even if some of them are in the MySQL table. Here is my example: <?PHP $host = "XXX"; $user = "XXX"; $pwd = "XXX"; $filename = "C:\aaron.csv"; $fh = fopen($filename, 'r'); $theData = fread($fh, filesize($filename)); fclose($fh); $line = explode("\r\n", $theData); mysql_connect($host, $user, $pwd); mysql_select_db("database") or die("Error: " . mysql_error()); foreach ($line as $key => $value) { $info = explode("\t", $value); $info[1] = trim($info[1]); $empno = $info[1]; echo $info [1]; echo "<br>"; echo $empno; echo "<br>"; $query = "SELECT lastname, firstname FROM name WHERE empnumber = '$empno'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $lastname = $row['lastname']; $firstname = $row['firstname']; echo $row['lastname']; echo "<br>"; echo $lastname; echo "<br>"; echo $row['firstname']; echo "<br>"; echo $firstname; echo "<br><br>"; } mysql_close(); ?> Any help would be great thank you. This is driving me nuts.
  14. I am going to have to go back through my PHP documentation. Who's to say there isn't a function in PHP for what I want? There are many many MySQL-based functions in PHP.
  15. The first example did not work tried it several ways. Always resulted in a MySQL error or PHP error. So I guess it is back to putting it through multiple elseif statements. This is not really a big deal, but I consider this to be a complete disregard for time and money from a project management perspective.
  16. I am trying the first example. I will let you know. I think we posted out of order somewhere there. Sorry.
  17. This is the example I am trying to avoid. There are many possibilities for NULL variables here other than just the one (minutes), and just because one variable is NULL doesn't mean they will all be NULL. So I would have to use an elseif not just for each variable, but for each variable being NULL yet possibly not others. I have that in place now and it works fine, but I am trying to avoid development time by eliminating this if I can.
  18. I will try this example then and see what happens. Hopefully this will work. Yes. The default value is applied when you insert a new record but don't specify a value for that column.
  19. Or maybe I should get back to the requirements of what the script must do... A user either enters or does not enter a value for form field (minutes) and submits the form. The value of this form field must be written to a MySQL table record along with the other variables this form contains. If the resulting form variable $_POST['minutes'] is NULL, then the MySQL table record should be either UPDATED or INSERTED with a NULL value. Else, the MySQL table record should be UPDATED or INSERTED with the value that was entered in the form field (minutes).
  20. The default value in the database is NULL. Otherwise I wouldn't bother anyone with this.
  21. How about in the case of an INSERT? I do that also in a similar scenario if there is currently no record. The problem I am having is that during an INSERT, instead of a blank form field resulting in NULL in the MySQL table it results in an empty string (''). I want the blank HTML form field to result in a NULL value in the database. Also during an UPDATE, if the form field is left blank, I want the value in the database to be overwritten with NULL. If a value is entered into the form field, the value in the database should be overwritten with the value that is entered.
  22. So should it be?: $minutes = (empty($_POST['minutes'])) ? "NULL" : $_POST['minutes']; $query4 = "UPDATE attendance SET hours = '$hours', minutes = $minutes, code = '$code', notes = '$notes' WHERE empno = '$empno' AND year = '$year' AND month = '$month' AND day = '$day'"; $result4 = mysql_query($query4) or die(mysql_error());
  23. Edited - didn't realize what you were saying.
  24. I am pretty sure most forums have seen this problem before, but I can't seem to get the correct search terms to find the correct solution. Say I have: $minutes = (empty($_POST['minutes'])) ? NULL : $_POST['minutes']; Then later I do this $query4 = "UPDATE attendance SET hours = '$hours', minutes= '$minutes', code = '$code', notes = '$notes' WHERE empno = '$empno' AND year = '$year' AND month = '$month' AND day = '$day'"; $result4 = mysql_query($query4) or die(mysql_error()); If $minutes is NULL, it updates an empty string to the database instead of a NULL MySQL value. How do I make PHP aware of the fact that I want NULL and not an empty string?
  25. This is obviously my first exposure to the ternary operator in PHP, but I love it. What I needed was something like this: $newvar = (empty($_POST['newvar'])) ? NULL : $_POST['newvar']; Just knowing that the ternary operator exists is going to make my life so much easier.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.