自定义字段中的PHP更新数据库

时间:2015-11-12 08:37:41

标签: php

我已经调试了大约3个小时,我无法解决这个问题。 我只是不想更新一个或多个不更新所有字段或更新从字段获取所有数据库行的字段。

这是我的代码

$query_account = mysql_query("SELECT * FROM `user` WHERE `id`='$db_id'");
    $account_row = mysql_fetch_assoc($query_account);
    $db_permission = $account_row['permission'];
    $db_flogin = $account_row['first_login'];
    $db_username = $account_row['username'];
    $db_fname = $account_row['fname'];
    $db_mname = $account_row['mname'];
    $db_lname = $account_row['lname'];
    $db_email = $account_row['email'];
    $db_bday = $account_row['birthday'];
    $db_nationality = $account_row['nationality'];
    $db_phone = $account_row['phone'];
    $db_address = $account_row['address'];
    $db_gender = $account_row['gender'];
    $db_password = $account_row['password'];
    $db_recpassword = $account_row['recovery_password'];
    if(isset($_POST['as_savebtn'])){
        $fname = $_POST['as_fname'];
        $mname = $_POST['as_mname'];
        $lname = $_POST['as_lname'];
        $email = $_POST['as_email'];
        $nationality = $_POST['as_nationality'];
        $phone = $_POST['as_phone'];
        $address = $_POST['as_address'];
        $pass = $_POST['as_pass'];
        $cpass = $_POST['as_cpass'];
        $asc_pass = $_POST['asc_pass'];
        $recpass = $_POST['as_recpass'];
        $crecpass = $_POST['as_crecpass'];
        if($asc_pass!=null){
            if($asc_pass==$db_password){
                if($pass==$cpass){
                    if($recpass==$crecpass){
                        $pass_length = strlen($pass);
                        if($pass_length>=1 && $pass_length<5){
                            $err_msg = "<font color='red'> Settings didn't changed, your password must be at least 5 characters!</font>";
                        }else{
                            $recpass_length = strlen($recpass);
                            if($pass_length>=1 && $recpass_length<4){
                                $err_msg = "<font color='red'> Settings didn't changed, your recovery password must be at least 4 characters!</font>";
                            }else{

                                if(filter_var($email, FILTER_VALIDATE_EMAIL)){
                                    if($fname==null || $fname==""){
                                        $fname = $db_fname;
                                    }else if($mname==null || $mname==""){
                                        $mname = $db_mname;
                                    }else if($lname==null || $lname==""){
                                        $lname = $db_lname;
                                    }else if($email==null || $email==""){
                                        $email = $db_email;
                                    }else if($nationality==null || $nationality==""){
                                        $nationality = $db_nationality;
                                    }else if($phone==null || $phone==""){
                                        $phone = $db_phone;
                                    }else if($address == null || $address== "" ){
                                        $address = $db_address;
                                    }else if($pass==null || $pass == ""){
                                        $pass = $db_password;
                                    }else if($recpass == null || $recpass ==""){
                                        $recpass = $db_recpassword;
                                    }
                                    mysql_query("UPDATE `user` SET `fname`='$fname',`mname`='$mname',`lname`='$lname',`email`='$email',`nationality`='$nationality',`phone`='$phone',`address`='$address',`password`='$pass',`recovery_password`='$recpass' WHERE `id`='$db_id'") or die(mysql_error());

                                }else if($email=="" || $email ==null){
                                    if($fname==null || $fname==""){
                                        $fname = $db_fname;
                                    }else if($mname==null || $mname==""){
                                        $mname = $db_mname;
                                    }else if($lname==null || $lname==""){
                                        $lname = $db_lname;
                                    }else if($email==null || $email==""){
                                        $email = $db_email;
                                    }else if($nationality==null || $nationality==""){
                                        $nationality = $db_nationality;
                                    }else if($phone==null || $phone==""){
                                        $phone = $db_phone;
                                    }else if($address == null || $address== "" ){
                                        $address = $db_address;
                                    }else if($pass==null || $pass == ""){
                                        $pass = $db_password;
                                    }else if($recpass == null || $recpass ==""){
                                        $recpass = $db_recpassword;
                                    }
                                    mysql_query("UPDATE `user` SET `fname`='$fname',`mname`='$mname',`lname`='$lname',`email`='$email',`nationality`='$nationality',`phone`='$phone',`address`='$address',`password`='$pass',`recovery_password`='$recpass' WHERE `id`='$db_id'") or die(mysql_error());

                                }else{
                                    $err_msg = "<font color='red'> Settings didn't changed, you have entered invalid email!</font>";
                                }
                            }
                        }
                    }else{
                        $err_msg = "<font color='red'> Settings didn't changed, recovery password doesn't match!</font>";
                    }
                }else{
                    $err_msg = "<font color='red'> Settings didn't changed, password doesn't match!</font>";
                }
            }else{
                $err_msg = "<font color='red'> Settings didn't changed, you have entered an Invalid Password!</font>";
            }
        }else{
            $err_msg = "<font color='red'> Settings didn't changed, you have entered an Invalid Password!</font>";
        }
    }
有人能帮帮我吗?我非常需要帮助:(提前谢谢

0 个答案:

没有答案