Hello,

I have little knowledge with PHP and I was assigned to try to fix some of the things that don't work in a website. The website basically deals with two different users, a trader who can post articles and a blogger who can post blogs. When a user registers to become a trader though, he is registered as a blogger. I checked the database and everyone who tried to register as a trader was saved as a user. I think the problem is in the register process method. I attached a copy of the codes. Since my knowledge is very limited, i'm not exactly sure what's wrong. Can you please take a look at it and let me know. I'm open to any thoughts and suggestions.

public function process()
    {
        $date = date('Y-m-d');
        $userid = uniqid();
        $captchaError = '';
        if($this->input->post('Submit'))
        {
//---------------------------------FORM VALIDATION STARTS HERE---------------------------------
            $this->form_validation->set_error_delimiters('', '');
            $this->form_validation->set_rules('fname', 'Full name','required');
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[tbl_user.email]');
            $this->form_validation->set_rules('password', 'password', 'trim|required|min_length[6]|matches[cpassword]');
            $this->form_validation->set_rules('cpassword', 'Password confirmation', 'required');
            $this->form_validation->set_rules('mycheck[]', 'Buyer or Supplier','required');
            $this->form_validation->set_rules('material[]', 'materials','required');
            $this->form_validation->set_rules('company', 'Company name', 'required');
            $this->form_validation->set_rules('cname', 'Contact name','required');
            $this->form_validation->set_rules('cemail', 'Contact email', 'required|valid_email');
            $this->form_validation->set_rules('nation', 'Country', 'required');
            $this->form_validation->set_rules('city', 'City','required');
            $this->form_validation->set_rules('fax');
            $this->form_validation->set_rules('mobile');
            $this->form_validation->set_rules('phone');
            $this->form_validation->set_rules('website');
            $this->form_validation->set_rules('address');
            $this->form_validation->set_rules('zip');
            $this->form_validation->set_rules('content', 'Tell something about urself', 'required');
            $this->form_validation->set_rules('captchaText', 'captcha text', 'required');
//-----------------------------------FORM VALIDATION ENDS HERE--------------------------------------


//------------------------------------CAPTCHA CHECK------------------------------------------
            if($this->input->post('captchaText'))
            {
                $expiration = time()-7200; // Two hour limit
                $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);

            // Then see if a captcha exists:
                $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
                $binds = array($_POST['captchaText'], $this->input->ip_address(), $expiration);
                $query = $this->db->query($sql, $binds);
                $row = $query->row();

                if ($row->count == 0)
                {
                $captchaError =  "You must submit the word that appears in the image";
                }
            }
//--------------------------------------CAPTCHA CHECK ENDS HERE----------------------------

//----------------------------------FORM VALIDATION RETURN ERRORS---------------------------
            if ($this->form_validation->run() == FALSE || $captchaError!='')
            {
            $data['captcha'] = $this->getCaptcha();
            $data['captchaError'] = $captchaError;
            $data['pageTitle']='Registration | Error';
            $this->load->view('register-trader',$data);
            }
//-----------------------------------------------END---------------------------------------

//---------------------------------------INSERT DATA INTO DATABASE-----------------------
            else
            {
            if($this->input->post('material'))
                {
                $material = '';
                foreach($this->input->post('material') as $value)
                {
                $material.= $value.',';
                }
            $material = rtrim($material,',');
            }
            $mycheck = $this->input->post('mycheck');
            $mycheckOne = '';
            $mycheckTwo = '';
            if(!empty($mycheck[0])){$mycheckOne = $mycheck[0];}
            if(!empty($mycheck[1])){$mycheckTwo = $mycheck[1];}
            $config['file_name'] = uniqid(); 
            $config['upload_path'] = UP_PATH;
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '1000';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';
            $this->load->library('upload', $config);
            if ( ! $this->upload->do_upload('userfile1'))
            {               
                $error = $this->upload->display_errors();
                $data = array(
                  'supplier'=>$mycheckOne,
                  'buyer'=>$mycheckTwo,
                  'title'=>$this->input->post('company'),
                  'cname'=>$this->input->post('cname'),
                  'material'=>$material,
                  'email'=>$this->input->post('email'),
                  'phone'=>$this->input->post('phone'),
                  'fax'=>$this->input->post('name'),
                  'mobile'=>$this->input->post('mobile'),
                  'web'=>$this->input->post('website'),
                  'country'=>$this->input->post('nation'),
                  'city'=>$this->input->post('city'),
                  'address'=>$this->input->post('address'),
                  'zip'=>$this->input->post('zip'),
                  'content'=>$this->input->post('content'),
                  'date'=>$date,
                  'userid'=>$userid,
                  'status'=>0
                );

            }   
            else
            {
                $data = array('upload_data' => $this->upload->data()); 
                $filepath = $data['upload_data']['file_name'];
                $config['image_library'] = 'gd2';
                $config['source_image'] = UP_PATH.$filepath;
                $config['new_image'] = UP_PATH.'thumbs/';
                $config['create_thumb'] = TRUE;
                $config['thumb_marker'] = '';
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 75;
                $config['height'] = 50;
                $this->load->library('image_lib', $config);
                $this->image_lib->resize();

                $data = array(
                  'supplier'=>$mycheckOne,
                  'buyer'=>$mycheckTwo,
                  'title'=>$this->input->post('company'),
                  'cname'=>$this->input->post('cname'),
                  'material'=>$material,
                  'email'=>$this->input->post('email'),
                  'phone'=>$this->input->post('phone'),
                  'fax'=>$this->input->post('fax'),
                  'mobile'=>$this->input->post('mobile'),
                  'web'=>$this->input->post('website'),
                  'country'=>$this->input->post('nation'),
                  'city'=>$this->input->post('city'),
                  'address'=>$this->input->post('address'),
                  'zip'=>$this->input->post('zip'),
                  'content'=>$this->input->post('content'),
                  'image'=>$filepath,
                  'date'=>$date,
                  'userid'=>$userid,
                  'status'=>0
                  );

            }   
            $this->db->insert(TBL_CLA,$data);

            $log_type = 'trader';
            $password = do_hash($this->input->post('password'));
            $dataOne = array(
                  'password'=>$this->security->xss_clean($password),
                  'fname'=>$this->security->xss_clean($this->input->post('fname')),
                  'email'=>$this->security->xss_clean($this->input->post('email')),
                  'log_type'=>$log_type,
                  'userid'=>$userid,
                  'status'=>0,
                  'date'=>$date,
                  'active'=>1
                  );
            $this->db->insert(TBL_USE,$dataOne);

            $this->session->set_userdata('fname', $this->input->post('fname'));
            redirect(base_url().'register/activate');
            }
            }
            if($this->input->post('Login'))
            {
//---------------------------------FORM VALIDATION STARTS HERE---------------------------------
            $this->form_validation->set_error_delimiters('', '');
            $this->form_validation->set_rules('fname', 'Full name','required');
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[tbl_user.email]');
            $this->form_validation->set_rules('password', 'password', 'trim|required|min_length[6]|matches[cpassword]');
            $this->form_validation->set_rules('cpassword', 'Password confirmation', 'required');
            $this->form_validation->set_rules('captchaText', 'captcha text', 'required');
//-----------------------------------FORM VALIDATION ENDS HERE--------------------------------------


//------------------------------------CAPTCHA CHECK------------------------------------------
            if($this->input->post('captchaText'))
            {
                $expiration = time()-7200; // Two hour limit
                $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);

            // Then see if a captcha exists:
                $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
                $binds = array($_POST['captchaText'], $this->input->ip_address(), $expiration);
                $query = $this->db->query($sql, $binds);
                $row = $query->row();

                if ($row->count == 0)
                {
                $captchaError =  "You must submit the word that appears in the image";
                }
            }
//--------------------------------------CAPTCHA CHECK ENDS HERE----------------------------

//----------------------------------FORM VALIDATION RETURN ERRORS---------------------------
            if ($this->form_validation->run() == FALSE || $captchaError!='')
            {
            $data['captcha'] = $this->getCaptcha();
            $data['captchaError'] = $captchaError;
            $data['pageTitle']='Registration | Error';
            $this->load->view('register-blogger',$data);
            }
//-----------------------------------------------END---------------------------------------

//---------------------------------------INSERT DATA INTO DATABASE-----------------------
            else
            {

            $date = date('Y-m-d');
            $log_type = 'blogger';
            $password = do_hash($this->input->post('password'));
            $dataOne = array(
                  'password'=>$this->security->xss_clean($password),
                  'fname'=>$this->security->xss_clean($this->input->post('fname')),
                  'email'=>$this->security->xss_clean($this->input->post('email')),
                  'log_type'=>$log_type,
                  'userid'=>$userid,
                  'status'=>0,
                  'date'=>$date,
                  'active'=>0
                  );
            $this->db->insert(TBL_USE,$dataOne);
            $data['link'] = 'http://www.arabrecycling.org/activate/created/'.$userid;
            $data['name'] = $this->input->post('fname');
            $message = $this->load->view('includes/activate',$data, TRUE);
            $subject = 'Account Activation';
            $fromTest = 'The Arab Recycling Initiative';
            $this->userRegEmail('info@arabrecycling.org',$this->input->post('email'),$message,$subject,$fromTest);
            $this->session->set_userdata('fname', $this->input->post('fname'));
            redirect(base_url().'register/activate');
            }
            }


    }
//-------------------------------------------------------CAPTCHA CREATION STARTS HERE------------------------
    public function getCaptcha(){

            $this->load->library('common');
            $this->common = new common();

            $this->load->helper('captcha');
            $vals = array(
            'word' => $this->common->GetRandomCaptchaText(8),
            'img_path' => './captcha/',
            'img_url' => base_url().'captcha/',
            'font_path' => base_url().'system/fonts/Candice.ttf',
            'img_width' => '150',
            'img_height' => 30,
            'expiration' => 7200
            );

            $cap = create_captcha($vals);

            $data = array(
            'captcha_time' => $cap['time'],
            'ip_address' => $this->input->ip_address(),
            'word' => $cap['word']
            );

            $query = $this->db->insert_string('captcha', $data);
            $this->db->query($query);

            return $cap['image'];
    }
//--------------------------------------------------------CAPTCHA CREATION ENDS HERE------------------------------------------------
//--------------------------------------------------------CONFIGURING EMAIL------------------------------------------------
        public function userRegEmail($from,$to,$message,$subject,$fromTest){
             $email_config['protocol'] = 'mail';
             $email_config['mailtype'] = 'html';
             $this->email->initialize($email_config);

             $this->email->from($from, $fromTest);
             $this->email->to($to);         
             $this->email->subject($subject);
             $this->email->message($message); 
             $this->email->send();
    }


//--------------------------------------------------------EMAIL CONFIGURATION ENDS HERE------------------------------------------------
Member Avatar for diafol

The website basically deals with two different users, a trader who can post articles and a blogger who can post blogs. When a user registers to become a trader though, he is registered as a blogger. I checked the database and everyone who tried to register as a trader was saved as a user.

Doesn't make sense. You have 2 types of user: 'trader' and 'blogger'. So what's the third type 'user'?

that's it. I only have two users

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.