Hello,
I need your help please, I can not save the user in the database after it has been created.
you will find the codes attached. Thank you for your reards.
register controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Register extends MX_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
if ($this->db->table_exists('users'))
{
$this->db->where('user_role',1);
$admin = $this->db->get('users')->row();
if(!empty($admin)){
redirect(site_url('admin/login'));
}
}
if ($this->input->server("REQUEST_METHOD") == "POST")
{
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'lang:name', 'required');
$this->form_validation->set_rules('email', 'lang:email', 'trim|required|valid_email|max_length[128]|is_unique[users.email]');
$this->form_validation->set_rules('username', 'lang:username', 'trim|required|is_unique[users.username]');
$this->form_validation->set_rules('password', 'lang:password', 'required|min_length[6]');
$this->form_validation->set_rules('conf', 'lang:confirm_password', 'required|matches[password]');
if ($this->form_validation->run()==true)
{
//$save['id'] = 1;
$save['name'] = $this->input->post('name');
$save['username'] = $this->input->post('username');
$save['password'] = sha1($this->input->post('password'));
$save['email'] = $this->input->post('email');
$save['user_role'] = 1;
//echo '<pre>'; print_r($save);die;
$this->auth->save($save);
$this->session->set_flashdata('message', 'Registration Success');
redirect('admin/login');
}
}
$this->load->view('register');
}
function check_table()
{
if ($this->db->table_exists('users'))
{
echo '
<div class="header">'.lang("register_new_admin").'</div>
<form action="'.site_url("register").'" method="post" id="register_form">
<div class="body bg-gray">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="'.lang("name").'"/>
</div>
<div class="form-group">
<input type="text" name="username" class="form-control" placeholder="'.lang("username").'"/>
</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="'.lang("password").'"/>
</div>
<div class="form-group">
<input type="password" name="conf" class="form-control" placeholder="'.lang("confirm_password").'"/>
</div>
<div class="form-group">
<input type="text" name="email" class="form-control" placeholder="'.lang("email").'"/>
</div>
</div>
<div class="footer">
<button type="submit" class="btn bg-olive btn-block">Register</button>
</div>
</form>
';
}else
{
echo 'error';
}
}
}
register view :
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php echo lang('register')?> | <?php echo lang('site_title_simple')?></title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap -->
<link href="<?php echo base_url('assets/plugins/bootstrap/bootstrap.min.css')?>" rel="stylesheet" type="text/css" />
<!-- Font Awesome -->
<link href="<?php echo base_url('assets/plugins/font-awesome/font-awesome.min.css')?>" rel="stylesheet" type="text/css" />
<!-- Ionicons -->
<link href="<?php echo base_url('assets/css/ionicons.min.css')?>" rel="stylesheet" type="text/css" />
<!-- iCheck -->
<link rel="stylesheet" href="<?php echo base_url('assets/plugins/iCheck/square/blue.css')?>">
<!-- Custom Theme Style -->
<link href="<?php echo base_url('assets/css/AdminLTE.css')?>" rel="stylesheet">
<link href="<?php echo base_url('assets/css/redactor.css')?>" rel="stylesheet" type="text/css" />
<link href="<?php echo base_url('assets/css/skins/_all-skins.min.css')?>" rel="stylesheet" type="text/css" />
<link href="<?php echo base_url('assets/css/custom.css')?>" rel="stylesheet" type="text/css" />
<!-- jQuery 2.0.2 -->
<script src="<?php echo base_url('assets/plugins/jQuery/jquery-2.2.3.min.js')?>"></script>
<script src="<?php echo base_url('assets/plugins/jQueryUI/jquery-ui.min.js')?>" type="text/javascript"></script>
<script src="<?php echo base_url('assets/plugins/bootstrap/bootstrap.min.js')?>" type="text/javascript"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<?php echo lang('site_title')?>
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<?php if(validation_errors()): ?>
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php echo validation_errors(); ?>
</div>
<?php endif; ?>
<p class="login-box-msg"><?php echo lang('register_new_admin')?></p>
<div id="login-box">
<form action="<?php echo site_url('register')?>" method="post" id="register_form">
<div class="form-group has-feedback">
<input type="text" name="name" class="form-control" placeholder="<?php echo lang('name')?>"/>
<span class="fa fa-list form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="text" name="username" class="form-control" placeholder="<?php echo lang('username')?>"/>
<span class="fa fa-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" name="password" class="form-control" placeholder="<?php echo lang('password')?>"/>
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" name="conf" class="form-control" placeholder="<?php echo lang('confirm_password')?>"/>
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="email" name="email" class="form-control" placeholder="<?php echo lang('email')?>"/>
<span class="fa fa-envelope form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat pull-right"><?php echo lang('register field submit')?></button>
</div>
<!-- /.col -->
</div>
</form>
</div>
</div>
<!-- /.login-box-body -->
</div>
<!-- /.login-box -->
<!-- iCheck -->
<script src="<?php echo base_url('assets/plugins/iCheck/icheck.min.js')?>"></script>
<script>
$(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
});
function check_table()
{
$.ajax({
url: '<?php echo site_url('register/register/check_table') ?>',
type:'POST',
success:function(result){
if(result=='error'){
check_table();
}else{
$('#login-box').html(result);
}
}
});
}
</script>
</body>
</html>
Admin controllers login :
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class login extends MX_Controller {
public function __construct()
{
parent::__construct();
}
function index()
{
$redirect = $this->auth->is_logged_in(false, false);
if($redirect)
{
redirect('admin/dashboard');
}
$this->load->helper('form');
$data['redirect'] = $this->session->flashdata('redirect');
$submitted = $this->input->post('submitted');
if ($submitted)
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$remember = $this->input->post('remember');
$redirect = $this->input->post('redirect');
$login = $this->auth->login_admin($username, $password, $remember);
$redirect = site_url('admin/dashboard');
if ($login)
{
if ($redirect == '')
{
$redirect = site_url('admin/dashboard');
}
redirect($redirect);
}
else
{
//this adds the redirect back to flash data if they provide an incorrect credentials
$this->session->set_flashdata('redirect', $redirect);
$this->session->set_flashdata('error', lang('authenication_failed'));
redirect('admin/login');
}
}
$this->load->view('login/login', $data);
}
function logout()
{
$this->auth->logout();
//when someone logs out, automatically redirect them to the login page.
$this->session->set_flashdata('message', lang('log_out'));
redirect('admin/login');
}
}
Attached Files
routes.php (Size: 1.55 KB / Downloads: 98)
config.php (Size: 13.22 KB / Downloads: 80)
install.php (Size: 4.44 KB / Downloads: 77)
register.php (Size: 3.16 KB / Downloads: 93)
user_role_model.php (Size: 2.35 KB / Downloads: 87)