在编辑模式下,密码不应更新

时间:2014-07-01 08:08:09

标签: php

当用户点击编辑按钮时,除了密码字段外,所有表单字段都将自动填满,点击更新按钮将更新记录。但我想如果用户不在更新模式下提供密码,则不应更新密码。我不知道该怎么办?请分享想法。先谢谢

代码

// Process action
if($action == 'Process')
{
    // checking errors
    $error_msgs         = array();

    // getting record if id
    $data = ($id) ? $db->getRow("SELECT * FROM `{$db_table}` WHERE `{$pcolumn_name}`='$id'") : FALSE;

    // if username already exist
    $is_exist_username = is_exists_record($db_table, $pcolumn_name, 'username', $username, $id);


    if(empty($firstname))
        $error_msgs['firstname']            = "First Name must have some value!";
    if(empty($lastname))
        $error_msgs['lastname']             = "Last Name must have some value!";
    if(empty($email))
        $error_msgs['email']                = "Email must have some value!";
    if(empty($username))
        $error_msgs['username']             = "Username must have some value!";
    if(empty($password))
        $error_msgs['password']             = "Password must have some value!";
    if(empty($repeatpassword))
        $error_msgs['repeatpassword']       = "Repeat Password must have some value!";
    if($password!=$repeatpassword)
        $error_msgs['repeatpassword']       = "The Passwords do not match!";
    if($is_exist_username)
        $error_msgs['is_exist_username']    = "Username already exists!";
    if(!empty($email) && !isValidEmail($email))
        $error_msgs['email']                = "Please enter valid Email!";
    //----------------------------------------------------------------------------- successful process
    if(count($error_msgs) == 0)
    {

        // db data bucket
        $data_for_db = array(
            'username'              => $username,
            'password'              => $password,
            'transaction_pwd'       => $transaction_pwd,
            'email'                 => $email,


        );
        // setting more data into db array & memcache array
        //$data_for_db['date_added'] = (!$id) ? $curr_date : $data['date_added'];

        // db data set bucket
        $data_setRecord['ID']           = (int)$id;
        $data_setRecord['db_table']     = $db_table;
        $data_setRecord['pcolumn_name'] = $pcolumn_name;
        $data_setRecord['where']        = "`{$pcolumn_name}`='$id'";
        //$data_setRecord['print_sql']  = 1; 
        $data_setRecord['data_for_db']  = $data_for_db;

        $affected = setRecord($data_setRecord);

        ($affected) 
            ? msgOk('Record saved Successfully!') 
            : msgAlert('Record could not be saved, Try Again!');
    } print msgsErrors($error_msgs);
} // if ends for form submit

1 个答案:

答案 0 :(得分:0)

$data_for_db = array(
            'username'              => $username,
            'password'              => $password,
            'transaction_pwd'       => $transaction_pwd,
            'email'                 => $email,


        );

你应该添加:

if ($data !== false) {
  unset($data_for_db['password']);
}