Hello again,
I have a form that updates an employee's information including a password for that employee. The form has a password field and what I would like is if the admin leaves that field empty, the users password remains unchanged in the database... but if the admin enters text into the password field then that text should update the database as the employees new password.
The problem is to do this I need to either insert or remove a portion of the sql query. (There's probably an easier way to do this that I'm not seeing at 5:30AM.) But I don't know how to store the query portion outside of the actual query and then insert it when needed.
So let's say this is the basic query. This is what I want if the password FORM field is EMPTY:
UPDATE employees SET
employee_fullname = '".mysql_real_escape_string($_POST['employee_fullname'])."'
WHERE employee_username = '".mysql_real_escape_string($_POST['un'])."'";
But if the admin fills in the password FORM field, I want to insert an additional portion of sql to update the password field in the database like so:
UPDATE employees SET
employee_password = PASSWORD('".mysql_real_escape_string($_POST['employee_password'])."'),
employee_fullname = '".mysql_real_escape_string($_POST['employee_fullname'])."'
WHERE employee_username = '".mysql_real_escape_string($_POST['un'])."'";
So essentially if the admin enters a password into the update record form - include the following sql in the query - otherwise don't add the sql.
employee_password = PASSWORD('".mysql_real_escape_string($_POST['employee_password'])."'),
How would I store that sql string in a variable or something and then insert it into the query at the appropriate time??
Thanks again!
Peter