Welcome Guest, Not a member yet? Register   Sign In
[Solved] Migrations With Input Post Question
#1

[eluser]riwakawd[/eluser]
I have tried to load my migrations with input post, number for my migrations is 002_user;

I thought I might of been able to do it via migrations. Not inserting data in to user table

Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_User extends CI_Migration {
    
   public function up() {
      if(!$this->db->table_exists('user')) {
         $this->db->insert('user',
            array('username' => $this->input->post('username'),
            'password' => sha1($this->input->post('password')),
            'email' => $this->input->post('email')
         ));
      }
   }

   public function down(){
    
   }
      
}

Controller
Code:
$this->load->library('form_validation');

$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'trim|shar1|required|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required');

if ($this->form_validation->run() == false) {

    $this->load->view('template/step_5', $data);

} else {

    $this->load->library('migration');

    if($this->migration->version(2) == true) {

        redirect('setup/step_6');

    } else {

        redirect('setup/error');

    }
    
}


It can work in the controller by adding this


Code:
if ($this->form_validation->run() == false) {

$this->load->view('template/step_5', $data);

} else {

$this->db->insert('user', array('username' => $this->input->post('username'),'password' => sha1($this->input->post('password')),'email' => $this->input->post('email')));
  redirect('setup/step_6');
  
}
#2

[eluser]riwakawd[/eluser]
I think I have to just to it via model is best works excellent now

Code:
public function database() {
   $this->load->helper('security');
   $this->load->helper('date');

   $username = $this->input->post('username');
   $password =  $salt . sha1($this->input->post('password'));
   $email = $this->input->post('email');
   $salt = $salt = substr(md5(uniqid(rand(), true)), 0, 9);
   $data = array(
      'user_id' => '1',
      'user_group_id' => '1',
      'username' => $username,
      'password' => $password,
      'salt' => $salt,
      'email' => $email,
      'date_added' => mdate('%Y-%m-%d %H:%i:%s', now())
   );
  
   $this->db->insert('user', $data);
}




Theme © iAndrew 2016 - Forum software by © MyBB