I am seeing a strange error when using the database class (global $DB). When I try to use the EE tag {username} to save the current logged in user into the database (non EE table located in the EE database), the user is saved as {username}.
When I echo the sql statement, the username is correct. But the value being saved in the database is: {username}
It should be systemadmin.
I have php parsing set to output.
The user that is logged in is “systemadmin”
Here is a sample of my code:
global $DB;
$username = '{username}';
$data = array(
'FirstName' => $_POST['FirstName'],
'LastName' => $_POST['LastName'],
'ModifiedBy' => $username
);
print_r($data);
$sql = $DB->update_string('Members', $data, "MemberID = 4584");
$DB->query($sql);
echo 'sql string: '.$sql;Here is the output from the print_r statement:
Array ( [FirstName] => FirstTest [LastName] => LastTest [ModifiedBy] => systemadmin)Here is the output from the echo statement:
sql string: UPDATE `Members` SET `FirstName` = 'FirstTest', `LastName` = 'LastTest', `ModifiedBy` = 'systemadmin' WHERE MemberID = 4584But when I view the database table, the ModifiedBy field is set to {username} and not systemadmin
From the db table row:
MemberID = 4584
FirstName = FirstTest
LastName = LastTest
ModifiedBy = {username} ==> should be systemadmin
Any ideas why is it saving it as {username} and not systemadmin?