用户个人资料未更新用户信息

时间:2018-12-29 19:12:58

标签: php codeigniter

在我的网站上创建用户个人资料编辑页面时遇到麻烦 提交按钮不起作用,我需要知道为什么它不起作用

这是我的控制器edit_profile函数

public function edit_profil()
{
    $this->load->helper(array('form','url'));

    $this->load->model('mStages');
    $email_user = $this->session->userdata('email');
    $utilisateur = $this->mStages->get_utilisateur($email_user);
    if(!$utilisateur) redirect('main_stage/afficher_dashboard');

    $data = array();
    $data['personne'] = $utilisateur;

    $this->load->library('form_validation');
    $this->form_validation->set_rules('nom','Nom','required');
    $this->form_validation->set_rules('prenom','Prénom','required');
    $this->form_validation->set_rules('mail','Email','required');
    $this->form_validation->set_rules('adresse','Adresse','required');
    $this->form_validation->set_rules('code_postal','Code postal','required');
    $this->form_validation->set_rules('tel','téléphone','required');
    $this->form_validation->set_rules('date_nais','Date de naissance','required');
    $this->form_validation->set_rules('num_secu','numéro de sécurité sociale','required');
    $this->form_validation->set_rules('mutuelle','Mutuelle','required');
    $this->form_validation->set_rules('obj_pro','Objectif pro','required');
    $this->form_validation->set_rules('motdepasse','Mot de passe','required');


    if($this->form_validation->run() == FALSE)
    {
        $this->load->view('form',$data);
    }
    else 
    {
        $update_profil = array (
            'statut'=> $this->input->post('statut'),
            'civilite' => $this->input->post('civilite'),
            'prenom' => $this->input->post('prenom'),
            'nom' => $this->input->post('nom'),
            'mail' => $this->input->post('mail'),
            'adresse' => $this->input->post('adresse'),
            'complement' => $this->input->post('complement'),
            'code_postal' => $this->input->post('code_postal'),
            'tel' => $this->input->post('tel'),
            'date_nais' => $this->input->post('date_nais'),
            'num_secu' => $this->input->post('num_secu'),
            'mutuelle' => $this->input->post('mutuelle'),
            'objectif_pro' => $this->input->post('obj_pro'),
            'Mot de passe' => $this->input->post('motdepasse'),

            );
            $utilisateur_id = $this->mStages->get_utilisateur_id($email_user);
            $this->mStages->update_personne($utilisateur_id,$update_profil); 
            redirect('main_stage/afficher_dashboard');          
    }
}

这是我想更新数据库中用户详细信息时的模型函数

public function update_personne($utilisateur_id,$data)
{
    $this->db->where('id_personne',$utilisateur_id);
    return $this->db->update('personne', $data);
}

最后是表单视图代码

<!DOCTYPE html>
 <html>
<head>
 <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="assets/css/form.css"> <link rel="shortcut icon" type="image/png"> <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet"> 
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<!-- Theme CSS -->
<link href="<?php echo base_url('assets/css/form.css');?>" rel="stylesheet"> 
<title>Mon Profil</title>
  <center><h1>Mon Profil</h1></center>
</head>
<body>

<form action="<?php echo base_url().'main_stage/edit_profil' ?>" method="POST">

    <label> Nom </label><input class="pseudo" id="pseudo" type="text"  name="nom" value="<?php echo set_value('nom',$personne->nom);?>" required=""> 
    <br>
    <br> 
    <label> Prenom </label><input class="pseudo" id="pseudo" type="text" name="prenom" value="<?php echo set_value('prenom',$personne->prenom);?>" required="">
    <br>
    <br>

    <label>Civilité</label>

    <div class="styled-select blue semi-square">

     <select id="carte" name="civilite">
         <option value="Mr" <?php if($personne->civilite == 'Mr'){ echo set_select('civilite', 'Mr', TRUE);} ?> >Mr</option>
         <option value="Mrs" <?php if($personne->civilite == 'Mrs'){ echo set_select('civilite', 'Mrs', TRUE);} ?>>Mrs</option>
         <option value="Autre" <?php if($personne->civilite == 'Autre'){ echo set_select('civilite', 'Autre', TRUE); }?>>Autre</option>
     </select>

    </div>

    <br> 
    <label> Mail </label><input class="pseudo" id="pseudo" type="mail" name="mail" value="<?php echo set_value('mail',$personne->mail);?>" required="">
    <br>

    <br> 
    <label> Adresse </label><input class="pseudo" id="pseudo" type="text" name="adresse" value="<?php echo set_value('adresse',$personne->adresse);?>" required="" >
    <br>

    <br> 
    <label> Complement </label><input class="pseudo" id="pseudo" type="text" name="complement" value="<?php echo set_value('complement',$personne->complement);?>">
    <br>

    <br> 
    <label> Code Postal </label><input class="pseudo" id="pseudo" type="text" name="code_postal" value="<?php echo set_value('code_postal',$personne->code_postal);?>" required="">
    <br>

    <br> 
    <label> Telephone </label><input class="pseudo" id="pseudo" type="text"  name="tel" value="<?php echo set_value('tel',$personne->tel);?>" required="" pattern="(01|02|03|04|05|06|07|08|09)[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}">
    <br>

    <br> 
    <label> Date de naissance </label><input type="date" name="date_naissance" value="<?php echo set_value('date_naissance',$personne->date_naiss);?>" class="pseudo" id="pseudo" required="">
    <br>

    <br> 
    <label> Numero de sécurité sociale </label><input type="text" class="pseudo" id="pseudo" name="num_secu" value="<?php echo set_value('num_secu',$personne->num_secu);?>" required="" pattern="[12][ \.\-]?[0-9]{2}[ \.\-]?(0[1-9]|[1][0-2])[ \.\-]?([0-9]{2}|2A|2B)[ \.\-]?[0-9]{3}[ \.\-]?[0-9]{3}[ \.\-]?[0-9]{2}">
    <br>

    <br> 
    <label> Mutuelle </label><input type="text" class="pseudo" id="pseudo" name="mutuelle" value="<?php echo set_value('mutuelle',$personne->mutuelle);?>" required="" >
    <br>

    <br> 
    <label> Objectif pro </label><input type="text" class="pseudo" id="pseudo" name="obj_pro" value="<?php echo set_value('obj_pro',$personne->objectif_pro);?>" required="" >
    <br>

    <br> 
    <label> Mot de passe </label><input type="text" class="pseudo" id="pseudo" name="motdepasse" value="<?php echo set_value('motdepasse',$personne->motdepasse);?>" required="" >
    <br>

    <br> 

    <center><input type="submit" id="button" value="Valider"></center>

    </div>

</form> 

</html>

我需要查看是否出错,因为当我尝试这段代码时,当我单击“提交”按钮时出现了404错误,该按钮应该将用户重定向到他的仪表板


已解决

我做到了,所以这就是控制器中的改变

$update_profil = array (
                'civilite' => $this->input->post('civilite'),
                'prenom' => $this->input->post('prenom'),
                'nom' => $this->input->post('nom'),
                'mail' => $this->input->post('mail'),
                'adresse' => $this->input->post('adresse'),
                'complement' => $this->input->post('complement'),
                'code_postal' => $this->input->post('code_postal'),
                'tel' => $this->input->post('tel'),
                'date_naiss' => $this->input->post('date_naissance'),
                'num_secu' => $this->input->post('num_secu'),
                'mutuelle' => $this->input->post('mutuelle'),
                'objectif_pro' => $this->input->post('obj_pro'),
                'motdepasse' => $this->input->post('motdepasse'),

                );
                $this->load->model('mStages');
                $utilisateur_id = $this->mStages->get_utilisateur_id($email_user);
                $this->mStages->update_personne($utilisateur_id,$update_profil); 
                redirect('main_stage/afficher_dashboard');

这是视图中的更改

<form method="POST">

0 个答案:

没有答案