Welcome Guest, Not a member yet? Register   Sign In
Login form with user name and password from database
#1

[eluser]naveen27[/eluser]
Hi Everyone,
I'm trying to do the login forn in codeigniter .when I submit the login form it showing error.


My Controller class

Code:
function validate_credentials()
    {
        $this->load->model('quiz_mode');
        $query = $this->quiz_mode->validate();
                
        if($query) // if the user's credentials validated...
        {
            $data = array(
                'admin_name' => $this->input->post('aname'),
                'is_logged_in' => true
            );
            $this->session->set_userdata($data);
             $this->load->view('logged_in_area');
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }
My Mode class
Code:
function validate()
    {
        $this->db->where('admin_email', $this->input->post('email'));
        $this->db->where('admin_password', $this->input->post('pwd'));
        $query = $this->db->get("tvr_admin_dt");

        if($query->num_rows == 1)
        {
            return true;
        }

    }

My View
Code:
<html>
<body>
    <form action="<?php echo base_url();?>index.php/quiz/validate_credentials"  method="post">
<table>
Email&lt;input type="text" name="email"/&gt; <br /><br />

Password&lt;input type="password" name="pwd"/&gt; <br /><br />
&lt;input type="submit" value="submit"/&gt;
<a href="&lt;?php echo base_url();?&gt;index.php/quiz/new_user">new user</a>
</table>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
when i submitting it showing

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Quiz::$session

Filename: controllers/quiz.php

Line Number: 40
an any one help me.....
Thank in Advance.
#2

[eluser]meer[/eluser]
please check your spellings
$query = $this->quiz_mode->validate();

can u please supply the full controller code...
#3

[eluser]naveen27[/eluser]
Hi meer,
Thanks for reply ...i am sending my controller Can you help me.

Code:
&lt;?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of quiz
*
* @author root
*/
class Quiz extends CI_Controller
{
    function __construct()
    {
        parent::__construct(); //you always have to call parent's constructor before ANYTHING
        $this->load->library('session');
      
    }

    
    function index()
    {
       $this->load->view('login_view');
    }
      
   function validate_credentials()
    {
        $this->load->model('quiz_mode');
        $query = $this->quiz_mode->validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'admin_name' => $this->input->post('aname'),
                'is_logged_in' => true
            );
                        $this->load->library('session');
            $this->session->set_userdata($data);
            $this->load->view('logged_in_area');
        }
        else // incorrect username or password
        {
            $this->index();
        }
             //$this->load->view('logged_in_area');
    }

    function logout()
    {
        $this->session->sess_destroy();
        $this->index();
    }
        function is_logged_in()
    {
        $is_logged_in = $this->session->userdata('is_logged_in');
        if(!isset($is_logged_in) || $is_logged_in != true)
        {
            echo 'You don\'t have permission to access this page. <a href="../login">Login</a>';
            die();
            //$this->load->view('login_form');
        }
    }    
}
?&gt;
#4

[eluser]Abel A.[/eluser]
You loaded your session library twice.
#5

[eluser]naveen27[/eluser]
@berkguy thanks for reply ..
i put the comment.
If i submit the form it is redirecting the same page can you help...
Thanks in Advanced.
#6

[eluser]meer[/eluser]
kindly correct the num_row() function in your model , may be it will run then .....
if($query->num_rows == 1)
#7

[eluser]naveen27[/eluser]
Hi meer,
I changed but redirecting the same page can you help me ..
Thanks.
#8

[eluser]meer[/eluser]
can u modify your code as
controller

$email=$this->input->post('email');
$pwd=$this->input->post('pwd');
$this->load->model('quiz_mode');
$data = $this->quiz_mode->validate($email,$pwd);
if($data
{
put some code...
)
else
{
put the code on ret false.......
}
$this->load->view('your_view');

model

function validate($email,$pwd)
{
$this->db->select('email,pwd');
$this->db->from('tbl_name');
$this->db->where('email',$email);
$this->db->where('pwd',$pwd);
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result();
}
}
#9

[eluser]naveen27[/eluser]
Hi meer,
Validation working but session is not working Can you help .I struggling please can you help me

Thanks.
#10

[eluser]meer[/eluser]
ok i got it
the problem is that, you have not get the anname data from any where , so try this code to get the anname from your table

first u modify your model please

$this->db->select('anname');
$this->db->where('email',$this->input->post(email));
$this->db->where('pwd',$this->input->post(pwd));
$query = $this->db->get("your_tbl_name");
if($query->num_rows()>0)
{
return $query->result();
}


in your controller

if($query) // if the user's credentials validated...
{
$aname=$query->anname;
$data = array(
'admin_name' => $anname,
'is_logged_in' => true
);
$this->load->library('session');
$this->session->set_userdata($data);
$this->load->view('logged_in_area');
}

i hope this will help you




Theme © iAndrew 2016 - Forum software by © MyBB