Jump to content

pakenney38

Members
  • Posts

    90
  • Joined

  • Last visited

    Never

Posts posted by pakenney38

  1. 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" ?

     

     

  2. 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.

     

     

  3. 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?

  4. 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.

  5. 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.

  6. 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.

     

     

    this should only enter varables with info in them and ignore anyother and not alter the current set to null database deafualt set column

    <?php
    
    if(isset($_POST['submit'])){
    
    if( (!empty($varable_name)) || (!empty($varable_name)) || (!empty($varable_name))){
    
    $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());
    
    }else{}}; // dont do nothink with empty varables
    ?>
    
    
    

  7. I will try this example then and see what happens. Hopefully this will work.

     

     

    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());
    

     

    Yes.

     

    The default value is applied when you insert a new record but don't specify a value for that column.

  8. 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).

  9. 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.

  10. 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());
    

  11. 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?

×
×
  • 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.