0

Hello guys, my turn to ask a very simple question.

I already have a Mysql DB with querys working great.

I import data from Active Directory server, and one of the values is State, enabled or disabled, etc.
But this values came in a form of code:

512 = Enabled
514 = Disabled
544 = Enabled, Password Not Required
546 = Disabled, Password Not Required
66048 = Enabled, Password Doesnt Expire
66050 = Disabled, Password Doesn't Expire
66080 = Enabled, Password Doesn't Expire & Not Required

Now what i need is to insert the normal value in a new field

**Rude form:** If value is in row state is 512 insert into row state2 Enabled

Now i have the following code that is nor working:

    <?php
// error_reporting(0);
    // connect to the database
    include('config_users.php');
    $con = mysql_connect("$sqlhost","$sqluser",""); 
    if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 
    $sel = mysql_select_db($database, $con); 
    if (!$sel) 
    { 
    die('Could not select DB: ' . mysql_error()); 
    } 
$sql    = 'SELECT * FROM users WHERE Estado = 66048';
$result = mysql_query($sql, $con);

if (!$result) {
    echo "DB Error, could not query the database\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

while ($row = mysql_fetch_assoc($result)) {
    mysql_query("INSERT INTO users (State2) values ('Enabled')");
}

mysql_free_result($result);
?>

What am i doing wrong?
The last 3 hours where spent looking for a solution...

2
Contributors
7
Replies
17
Views
3 Years
Discussion Span
Last Post by diafol
0

I probably should use something like this:

if ($type == 512){
$type == "Enabled";
} elseif ($type == 514){
$type == "Disabled";
} elseif ($type == 544){
$type == "EnabledPassNotReq";
} elseif ($type == 546){
$type == "DisabledPassNotReq";
} elseif ($type == 66048){
$type == "EnabledPassNoExp";
} elseif ($type == 66050){
$type == "DisabledPassNoExp";
} elseif ($type == 66080){
$type == "EnabledPassNoExpNotReq";
} 
0

So State2 must = Estado?

This doesn't make much sense to me. The INSERT query is inserting a blank record except for the State2 field. Aren't you thinking of an UPDATE query?

UPDATE users SET State2 = Estado WHERE Estado = 66048

But this values came in a form of code:
512 = Enabled
514 = Disabled
544 = Enabled, Password Not Required
546 = Disabled, Password Not Required
66048 = Enabled, Password Doesnt Expire
66050 = Disabled, Password Doesn't Expire

This is so you can use bitwise operators. Very good :)

0

I have found it finaly, and its working: If Estado is 512 set State as Enabled... and so on... Thanks diafol.

mysql_query("UPDATE users SET State='Enabled' where Estado ='512'");
mysql_query("UPDATE users SET State='Disabled' where Estado ='514'");
mysql_query("UPDATE users SET State='Enabled, Password Not Required' where Estado ='544'");
mysql_query("UPDATE users SET State='Disabled, Password Not Required' where Estado ='546'");
mysql_query("UPDATE users SET State='Enabled, Password Doesnt Expire' where Estado ='66048'");
mysql_query("UPDATE users SET State='Disabled, Password Doesn't Expire' where Estado ='66050'");
mysql_query("UPDATE users SET State='Enabled, Password Doesn't Expire & Not Required' where Estado ='66080'");
0

My active Directory Query is finished, 1 week of work, and it can fetch data from ldap server,save it to mysql database.
In Every refresh it Truncats tables, and updates with new info.
I can export to Excel (CSV), and finaly i can make the state code readable.

Just one thing missing... Convert lastlogon tomestamp, but for now it is not needed.

0

When someone says it is not possible, or it is very dificoult or even worse, i only get eager to finish the work.

I get this script working in less then a week.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.