Php 用户名恢复代码未按预期工作

Php 用户名恢复代码未按预期工作,php,forms,codeigniter,validation,Php,Forms,Codeigniter,Validation,我正在为我工作的公司的一个网站上工作。它要求用户注册并登录。所有数据都存储在SQL数据库中。我正在尝试添加一个“丢失的用户名”表单,以便通过电子邮件恢复用户名。现在…我不是一个编码员。我只是一个相当有天赋的代码浏览者。我已经成功地完成了他们要求的所有内容,除此之外,我不太明白为什么它不起作用。我想是时候寻求一些帮助了 以下是我的控制器的代码: function forgot_pass(){ $data['page_title']=" Forgot Passw

我正在为我工作的公司的一个网站上工作。它要求用户注册并登录。所有数据都存储在SQL数据库中。我正在尝试添加一个“丢失的用户名”表单,以便通过电子邮件恢复用户名。现在…我不是一个编码员。我只是一个相当有天赋的代码浏览者。我已经成功地完成了他们要求的所有内容,除此之外,我不太明白为什么它不起作用。我想是时候寻求一些帮助了

以下是我的控制器的代码:

        function forgot_pass(){

          $data['page_title']=" Forgot Password ";
          $data['item']="Password";

          // initializing db keys
          $data['table_name'] ="physicians";
          $data['primary_key_name']="physician_id";

           //BOF Edit physician
           if( isset( $_REQUEST['physician_forgot_pass'] ) ){

              if ($this->form_validation->run('physician_forgot_pass'))
              {
                $physician_row=$this->model_site->check_physcian_retrive_password( $_REQUEST['username'],  encode_decode($_REQUEST['email'],'encode')  );
                //echo "<pre />"; print_r($physician_row); die;
                if($physician_row){

                    $physician_exist=1;

                    if($physician_row['approved']==1){ 

                       //Generate new Randmo password
                       $this->load->helper( 'get_random_password' );
                       $new_password=get_random_password(); //echo $new_password; die;

                       $update_data=array(
                                        'password'   => md5($new_password)
                                      );
                       $this->model_site->update_table('physicians', $update_data, 'username', $_REQUEST['username']  );


                       $this->load->helper( 'email_send' );

                       //GET SENDER EMAIL ADDRESS
                       $data['email_data']=$this->model_cms->get_single_record( 'email', 'email_id', 1 );
                       //echo "<pre />"; print_r($data['email_data']); die;

                       //Sending Mail To Physician
                       $physician_email = encode_decode($physician_row['email'],'decode');

                       $data['physician_email_msg']="Your New Password is ".$new_password;
                       $data['email_sent']=email_send( $data['email_data']['email'], $data['email_data']['email_name'], $physician_email  , "Retrive Password", $data['physician_email_msg']);
                       if($data['email_sent']){
                              $data['status']=1;
                              $data['status_message']="Your password has been sent to your mail at ".$physician_email;
                              $data['notification']=  array(
                                                        "notify_type"  => "notify_site_success",
                                                        "notify_message"   => $data['status_message']
                                                     );

                              //insert to audit log table
                              $audit_log_details="Physician <b>".encode_decode($physician_row['name'],'decode')."</b> ( Username : <b>".$physician_row['username']."</b> ) requested for retrieving lost passwords. A new password was sent to Physician. Email Address of the Physician is  <i>".$physician_email."</i> . ";
                              $audit_log_id = $this->model_cms->add_audit_log_record( $physician_row['physician_id'] , $physician_row['username'] , 'physician', "Retrieving lost passwords request ", $audit_log_details, time() );

                              $data['nbc_email_msg']=$audit_log_details."Here is the email below \n Your New Password is ".$new_password;
                              $data['email_sent']=email_send( $data['email_data']['email'], $data['email_data']['email_name'], $data['email_data']['email'], "Retrive Password", $data['nbc_email_msg']);
                       }
                       else {
                          $data['status']=0;
                          $data['status_message']="Error in sending mail to National Biological Corporation. Please try again later";
                          $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                       }

                    }
                    else {
                         $data['status']=0;
                         $data['status_message']="Your account is not approved yet. you will be able to request for retrive password after your account is approved.";
                         $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                    }
                }
                else {
                         $data['status']=0;
                         $data['status_message']="Sorry! Could not found physcian with this username and email.";
                         $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                }
              }
            }
           //EOF Edit physician

          $this->load->view('site/view_header',$data);
          $this->load->view('site/view_left_panel',$data);
          $this->load->view('site/view_physician_forgot_password',$data);
          $this->load->view('site/view_footer');
    }

    function forgot_userid(){

          $data['page_title']=" Forgot Username ";
          $data['item']="Username";

          // initializing db keys
          $data['table_name'] ="physicians";
          $data['primary_key_name']="physician_id";

           //BOF Edit physician
           if( isset( $_REQUEST['physician_forgot_userid'] ) ){

              if ($this->form_validation->run('physician_forgot_userid'))
              {
                $physician_row=$this->model_site->check_physician_get_userid( $_REQUEST['dea_number'],  encode_decode($_REQUEST['email'],'encode')  );
                //echo "<pre />"; print_r($physician_row); die;
                if($physician_row){

                    $physician_exist=1;

                    if($physician_row['approved']==1){ 

                        $this->load->helper( 'email_send' );

                       //GET SENDER EMAIL ADDRESS
                       $data['email_data']=$this->model_cms->get_single_record( 'email', 'email_id', 1 );
                       //echo "<pre />"; print_r($data['email_data']); die;

                       //Sending Mail To Physician
                       $physician_email = encode_decode($physician_row['email'],'decode');

                       $data['physician_email_msg']="According to our records, your registered username is ".$physician_row['username'];
                       $data['email_sent']=email_send( $data['email_data']['email'], $data['email_data']['email_name'], $physician_email  , "Your requested username reminder from phototherapydoctor.com", $data['physician_email_msg']);
                       if($data['email_sent']){
                              $data['status']=1;
                              $data['status_message']="Your username has been sent to your mail at ".$physician_email;
                              $data['notification']=  array(
                                                        "notify_type"  => "notify_site_success",
                                                        "notify_message"   => $data['status_message']
                                                     );

                              //insert to audit log table
                              $audit_log_details="Physician <b>".encode_decode($physician_row['name'],'decode')."</b> ( Username : <b>".$physician_row['username']."</b> ) requested for retrieving lost passwords. A new password was sent to Physician. Email Address of the Physician is  <i>".$physician_email."</i> . ";
                              $audit_log_id = $this->model_cms->add_audit_log_record( $physician_row['physician_id'] , $physician_row['username'] , 'physician', "Retrieving lost passwords request ", $audit_log_details, time() );

                              $data['nbc_email_msg']=$audit_log_details."Here is the email below \n Your New Password is ".$physician_row['username'];
                              $data['email_sent']=email_send( $data['email_data']['email'], $data['email_data']['email_name'], $data['email_data']['email'], "Retrive Password", $data['nbc_email_msg']);
                       }
                       else {
                          $data['status']=0;
                          $data['status_message']="Error in sending mail to National Biological Corporation. Please try again later";
                          $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                       }

                    }
                    else {
                         $data['status']=0;
                         $data['status_message']="Your account is not approved yet. You will be able to request username after your account is approved.";
                         $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                    }
                }
                else {
                         $data['status']=0;
                         $data['status_message']="Sorry! We could not find a physician with this DEA number and email.";
                         $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                }
              }
            }
           //EOF Edit physician

          $this->load->view('site/view_header',$data);
          $this->load->view('site/view_left_panel',$data);
          $this->load->view('site/view_physician_forgot_userid',$data);
          $this->load->view('site/view_footer');
    }
这是我的表单验证条目:

                  'physician_forgot_userid'=> array(
                               array(
                                        'field' => 'dea_number',
                                        'label' => 'DEA Number',
                                        'rules' => 'required'
                                     ),
                               array(
                                        'field' => 'email',
                                        'label' => 'Email',
                                        'rules' => 'required|valid_email'
                                     )
                                ),
最后,我的观点是:

<div class="middle_panel">

 <p style="color:#424A8D;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:15pt;font-weight:bold;">Retrieve Lost Username</p>

 <div class="physician_join_form">

    <?php echo  form_open('physician/forgot_userid'); ?>

       <div class="register_box_text">DEA Number : </div>
       <div class="register_box_field">
         <input name="dea_number" id="dea_number" value="<?php echo set_value('dea_number'); ?>" type="dea_number" size="20">
         <?php echo form_error('dea_number'); ?>
       </div>

       <div class="register_box_text">Email : </div>
       <div class="register_box_field">
         <input name="email" id="email" value="<?php echo set_value('email'); ?>" type="email" size="20">
         <?php echo form_error('email'); ?>
       </div>

       <div class="register_box_text" style="background:#F9F9F9;"> &nbsp; </div>
       <div class="register_box_field">
          <input type="submit" id="physician_forgot_userid" name="physician_forgot_userid" value="Submit">
       </div>

    <?php echo form_close(); ?>

 </div>

检索丢失的用户名

DEA编号:
  • 在您的视图中:将DEA编号字段的输入类型更改为有效的输入类型:[但这不会解决您的问题。]

    type=“dea\u编号”
  • 只需编写一个单独的函数和模型,从
    表中获取所有详细信息。
    

  • 控制器:在当前控制器内

    模型:内部模型/Model\u cms.php

    
    
        function fetch_details_model($dea_number) {
           $query = $this->db->get_where("physicians",array("dea_number"=>$dea_number));
           if( $query->num_rows() > 0 ) {
               return $query->row_array();
           }
           else {
               return false;
           }
        }
    
    


    像这样调用控制器函数:http://{YOURSITE}.com/{controller\u NAME}/fetch\u details\u ctrl/[DEA\u NUMBER]
    DEA_编号应该是用户将在恢复视图中提供的输入字段中输入的编号。
    如果这会产生结果,则表示问题不完全在于DEA编号。如果不是,则可能有两个原因:
    1.用户输入的DEA编号在数据库中不存在。
    2.电子邮件地址加密有一些问题,但您明确表示它以另一种方式工作正常[忘记密码]。但我没有看到该代码,所以我仍然有疑问。

  • 在您的视图中:将DEA编号字段的输入类型更改为有效的输入类型:[但这不会解决您的问题。]

    type=“dea\u编号”
  • 只需编写一个单独的函数和模型,从
    表中获取所有详细信息。
    

  • 控制器:在当前控制器内

    模型:内部模型/Model\u cms.php

    
    
        function fetch_details_model($dea_number) {
           $query = $this->db->get_where("physicians",array("dea_number"=>$dea_number));
           if( $query->num_rows() > 0 ) {
               return $query->row_array();
           }
           else {
               return false;
           }
        }
    
    


    像这样调用控制器函数:http://{YOURSITE}.com/{controller\u NAME}/fetch\u details\u ctrl/[DEA\u NUMBER]
    DEA_编号应该是用户将在恢复视图中提供的输入字段中输入的编号。
    如果这会产生结果,则表示问题不完全在于DEA编号。如果不是,则可能有两个原因:
    1.用户输入的DEA编号在数据库中不存在。


    2.电子邮件地址加密存在一些问题,但您明确表示,它可以通过另一种方式正常工作[忘记密码]但是我没有看到那些代码,所以我仍然有疑问。

    你有没有收到任何错误???你说的
    是什么意思所有的数据都存储在SQL数据库上?
    ?没有,没有任何php错误。只是一个网站错误,说没有使用这个dea号码和电子邮件的用户…只是说它在SQL数据库上。不确定这些信息可能有什么价值。只需点击我想提一下。其他一切都可以。我知道这一点,我在下面的行中将“userid”改为“password”,它可以工作,但错误。它需要你输入用户名。然后它会通过数据库将你的用户名发电子邮件给你…$medicine\u row=$this->model\u site->check\u medicine\u get\u useri你有什么错误吗ean by
    所有数据都存储在_SQL\u数据库上
    ?不,没有任何php错误。只是一个网站错误,说没有拥有此dea号码和电子邮件的用户……只是说它在SQL数据库上。不确定该信息可能有什么价值。我想我会提到它。其他一切都可以。我知道这一点,我在下面将“userid”改为“password”由于行,它工作,但错误。它要求您输入您的用户名。然后它将通过电子邮件从数据库向您发送您的用户名…$medicine\u row=$this->model\u site->check\u medicine\u get\u userid谢谢!我一定会很快尝试,然后更新。我感谢您的关注和帮助。好的,我尝试了这个,没有任何问题结果。虽然,很可能是我做错了什么。我应该把它添加到我当前的模型和控制器中,还是创建新的单独的模型和控制器?除了一般编辑之外,我真的不知道我在做什么。我确实知道,做原始构建/设计的人有一种定制东西的倾向,有点不合标准。而且,如果它证明不管怎么说,这个网站在公众可以看到的东西和内容管理系统之间是“分裂”的。两个模型和两组视图,模型库网站和模型库cms。其他的一切似乎都是共享的。这是相当多的评论…!我编辑了我的答案。如果它仍然对你没有帮助,我仍然很乐意帮助你。首先,我真的这么做了感谢您对我的问题的关注。我尽了您最大的理解力和能力尝试了您所描述的内容,但没有成功,尽管我不太清楚您所说的“像这样调用控制器函数”是什么意思“.我在学习的过程中了解到了其中的大部分,我觉得我应该/需要更详细地了解这意味着什么。我编辑了我的Q,并在代码中添加了密码部分以供审阅。“像这样调用控制器函数:”表示您必须在浏览器地址栏上键入的URL是我在顶部输入的URL。现在,在检查您的检索密码后,第二点被排除。问题肯定出在DEA编号上!您输入的号码可能不存在于数据库中/可能以其他格式存储。谢谢!我一定会很快尝试,然后更新。我感谢你的关注和帮助。好的,我试了一下,没有结果。尽管如此,我很可能做错了什么。我应该把它添加到我当前的模型中吗
    
    
        function fetch_details_model($dea_number) {
           $query = $this->db->get_where("physicians",array("dea_number"=>$dea_number));
           if( $query->num_rows() > 0 ) {
               return $query->row_array();
           }
           else {
               return false;
           }
        }