Welcome Guest, Not a member yet? Register   Sign In
Need to post twice to display flashdata message.
#1

[eluser]djalilk[/eluser]
Hi everybody,
I am new to codeIgniter and trying to create a login system, and didn't find any solution to my problem
: when I try to login, if the username or the password is wrong the flashdata message is displayed only if I submit my form twice.

here is the controller function:
Code:
function verify(){
if ($this-> input->post('username')){
$user = $this->input->post('username');
$password = $this->input->post('password');
$this->Admin->verifyAdmin($user,$password);

if(isset($_SESSION['userid'])) {
if($_SESSION['userid'] > 0){
redirect('/admin/dashboard/','refresh');
}



}
}

$data['main'] = 'admin';
$data['title'] = "Foctus | Admin Login";
$data['categories'] = $this->Category->getActiveCategories();
$this->load->vars($data);
$this->load->view('template',$data);
}

the model :

Code:
function verifyAdmin($user, $password){

$data= array();
$this->db->where('username', $user);
$this->db->where('password', $password);
$this->db->where('status', 'active');
$this->db->limit(1);
$Q = $this->db->get('admins');

if ($Q->num_rows() > 0){
$row = $Q->row_array();
$_SESSION['userid'] = $row['id'];
$_SESSION['username'] = $row['username'];

}



else{

$this->session->set_flashdata('error', 'Sorry, your username or password is incorrect!');



}

}

And the view :

Code:
<div id="pleft">
<h2> Please login to Access the Dashboard </h2>
&lt;?php
if($this->session->flashdata('error')) {
echo '<div class="message"> ';
echo '<p>'.$this->session->flashdata('error').'</p>';

echo'</div>';
}
?&gt;
&lt;?php
$userData = array('name'=>'username','id'=>'u','size'=>15);
$passwordData = array('name'=>'password','id'=>'p','size'=>15);
echo form_open("/welcome/verify/");
echo "<p> <label for='u'> Username </label> <br/> ";
echo form_input($userData)." </p> ";
echo "<p> <label for='p'> Password </label> <br/> ";
echo form_password($passwordData)." </p> ";
echo form_submit('submit','login');
echo form_close();
?&gt;
</div>

Please help me
Thank you.


Messages In This Thread
Need to post twice to display flashdata message. - by El Forum - 05-01-2009, 03:55 PM
Need to post twice to display flashdata message. - by El Forum - 05-01-2009, 07:53 PM
Need to post twice to display flashdata message. - by El Forum - 05-02-2009, 03:02 AM
Need to post twice to display flashdata message. - by El Forum - 05-02-2009, 03:37 AM
Need to post twice to display flashdata message. - by El Forum - 05-02-2009, 08:30 AM
Need to post twice to display flashdata message. - by El Forum - 05-02-2009, 10:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB