Welcome Guest, Not a member yet? Register   Sign In
login page errors
#1

[eluser]asmaa kamal[/eluser]
hi

iam beginner in using codeigniter

i try to code login page to my website

first:when loading the form the url is : http://localhost/t/index.php/main/login

t is the codeigniter folder which contains (application-userguide-system)
Quote:the problem is when login with "valid" or "non valid" email and password it gave me this message "your useremail/passward is invalid. " and the url is the same : http://localhost/t/index.php/main/login


i want it when putting avalid wmail >> it redirect me to "dashboard" page .

plz help me

in controller ( main.php)

Code:
<?php

class Main extends CI_Controller {
function Main()
{
parent::__construct();


$this->load->model('user_model');
$this->load->library('form_validation');


}

  public function login()
  { //echo current_url();
  
  $this->form_validation->set_rules('userEmail','email','trim|required|valid_email|callback_check_login');
   $this->form_validation->set_rules('userPassward','passward','trim|required|md5');
  
  if($this->form_validation->run()==TRUE)
  {
  
  // statement balwa
if($this->user_model->Login(array('userEmail'=>$this->input->post('userEmail'),'userPassward'=>$this->input->post('userPassword'))));
   {
    redirect('dashboard'); }
    
     redirect('main/login');}

  $this->load->view('main/login_form');

  }
  function index()
{
  
  $this->load->view('main/main_index');
}
function check_login($userEmail)
{
if ($this->input->post('userPassward'))
{
$user=$this->user_model->GetUsers(array('userEmail'=>$userEmail,'userPassward'=>md5($this->input->post('userPassword'))));
if($user) return true;
}
$this->form_validation->set_message('check_login','your useremail/passward is invalid.');
return false;


}
}

the user_model code :

Code:
<?php

class User_Model extends Model {

function _required($required,$data)
{
foreach($required as $field)
if(!isset($data[$field])) return false;
return true;

}


function AddUser($options=array())
{
if(!$this->_required(array('userEmail','userPassword'),$options)) return false;
$options=$this->_default(array('userStatus','active'),$options);
$this->db->insert('users',$options);
return $this->db->insert_id();





}
function UpdateUser($options=array())
{
if(!$this->_required(array('userId'),$options)) return false;
if(isset($options['userEmail']))
$this->db->set('userEmail',$options['userEmail']);
if(isset($options['userPassword']))
$this->db->set('userPassword',md5($options['userPassword']));
if(isset($options['userStatus']))
$this->db->set('userStatus',$options['userStatus']);
$this->db->update('users');
return $this->db->affected_rows();



}
function _default($defaults,$options)
{
return array_merge($defaults,$options);

}
function GetUsers($options=array())
{
if(isset($options['userId']))
$this->db->where('userId',$options['userId']);
if(isset($options['userEmail']))
$this->db->where('userEmail',$options['userEmail']);
if(isset($options['userStatus']))
$this->db->where('userStatus',$options['userStatus']);
if(isset($options['userPassword']))
$this->db->where('userPassword',$options['userPassword']);
if(isset($options['limit'])&&isset;($options['offset']))
$this->db->limit($options['limit'],$options['offset']);
else if(isset($options['limit']))
$this->db->limit($options['limit']);
if(isset($options['sortBy'])&&isset;($options['sortDirection']))
$this->db->order_by($options['sortBy'],$options['sortDirection']);
$query=$this->db->get('users');
if(isset($options['userId'])||isset($options['userEmail']))
return $query->row(0);
return $query->result();

}
function Login($options=array())
{
if(!$this->_required(array('userEmail','userPassword'),$options)) return false;
$user=$this->GetUsers(array('userEmail'=>$options['userEmail'],'userPassword'=>md5($options['userPassword'])));
if(!$user) return false;
$this->session->set_userdata('userEmail',$user->userEmail);

$this->session->set_userdata('userId',$user->userId);
return true ;
}

}






?>

the form_login code (put in view)

Code:
<?php echo form_open(site_url('main/login'))?>
<fieldset>
<legend>Login Form </legend>
<ul>
<li>
<label>Email</label>
&lt;?php echo form_input('userEmail',set_value('userEmail'))?&gt;
&lt;?php echo form_error('userEmail')?&gt;
</li>
<li>
<label>password</label>
&lt;?php echo form_password('userPassword')?&gt;
&lt;?php echo form_error('userPassword')?&gt;
</li>
<li>
&lt;?php echo form_submit('','login')?&gt;
</li>
</ul>

</fieldset>
&lt;?form_close()?&gt;


dashboard page :

Code:
&lt;?php
class Dashboard extends Controller{

function index()
{

echo "welcome to dashboard" ;

}

}


?&gt;


look at this config attributes :

Code:
$config['base_url'] = 'http://localhost/t/';

$config['index_page'] = 'index.php';


iam working at wamp

sorry for annoying u




#2

[eluser]asmaa kamal[/eluser]
oh this is the database
#3

[eluser]Jan_1[/eluser]
there is no else-statement between
redirect('dashboard'); }
and
redirect('main/login');}
?!
#4

[eluser]asmaa kamal[/eluser]
when i put else i got this error


( ! ) Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\t\application\controllers\main.php on line 28
#5

[eluser]Jan_1[/eluser]
Does look a little bit messy. Maybe you do start fresh with the (structur-)example from http://ellislab.com/codeigniter/user-gui...ationrules.

I've just seen, that you use also "Passward" as "Password". Is that alright?
#6

[eluser]asmaa kamal[/eluser]
ooh i noticed and i changed all to "password"

i put also else statement

it become


Code:
if($this->form_validation->run()==TRUE)
  {
  
if($this->user_model->Login(array('userEmail'=>$this->input->post('userEmail'),'userPassword'=>$this->input->post('userPassword'))))
  {redirect('dashboard'); }
else
   {redirect('main/login');}}
  

  
$this->load->view('main/login_form');

but still the same erorr

"your useremail/password is invalid." !!!
#7

[eluser]asmaa kamal[/eluser]
i changed the check_login method in main to

Code:
function check_login($userEmail)
{
if ($this->input->post('userPassword'))
{
$user=$this->user_model->GetUsers(array('userEmail'=>$userEmail,'userPassword'=>$this->input->post('userPassword')));
if($user) return true;
else
{$this->form_validation->set_message('check_login','your useremail/password is invalid.');
return false;}}


}
}


it doesnt redirect me to "dashboard" page

is it redirect problem?!?

help plz




Theme © iAndrew 2016 - Forum software by © MyBB