Welcome Guest, Not a member yet? Register   Sign In
Updating a unique field in database (example: account username or email)
#1

[eluser]Salvatore Formisano[/eluser]
Hi everyone,

I'll try to be short and straight to the point:

I am working on a codeigniter based website, and its users will have the possibility to edit their account (their name, username, email, password etc.)

When signing up, I used the following function to make sure that the username and the email were not already used for another account:

Code:
function unique($str, $field)
    {
        $CI =& get_instance();
        list($table, $column) = split("\.", $field, 2);
        $CI->form_validation->set_message('unique', 'The %s that you requested is unavailable.');
        $query = $CI->db->query("SELECT COUNT(*) dupe FROM $table WHERE $column = '$str'");
        $row = $query->row();
        return ($row->dupe > 0) ? FALSE : TRUE;
    }


now... my point is:

When a user wants to change his account's info, what kind of function could I use to make sure that unique fields (email,username) are not used by someone else already?


The "unique" function cannot be used for obvious reasons (if the user submits his "edit account" form with unique data unaltered, the function will return false because his data is already in the database)




I hope the question was clear enough, and that the solution can't be found in the user guide... because I really went through all of it (... well, almost!)



Thanks everyone,
Salvatore


Messages In This Thread
Updating a unique field in database (example: account username or email) - by El Forum - 12-10-2009, 02:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB