Welcome Guest, Not a member yet? Register   Sign In
user login error
#11

[eluser]Dam1an[/eluser]
If you're using native php sessions, you need to call session_start() at the start of your script, not sure if at the start of the controller is sufficient, as I always had it at the very start of the file (normally index.php), but any point before you call it should do
#12

[eluser]learning_php[/eluser]
I added the session_start() but stil get the error

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: username

Filename: models/MAdmins.php

Line Number: 18
#13

[eluser]Dam1an[/eluser]
Yeah, the session start was solving the other error (Undefined variable: _SESSION)

I'm assuming that row actually exists in the db Wink
Try calling it by ID, and see if you can access the username that way
#14

[eluser]Zeeshan Rasool[/eluser]
Did you check that the opening PHP tag for controller model and view is fine. I mean some times we put some fake characters or some blank spaces in our page. please check and clear if any exist.

i-e
Code:
asdsad<?php

///your code here..

?>
#15

[eluser]TheFuzzy0ne[/eluser]
If the $_SESSION variable is not available, there's a good chance that you haven't loaded the session class. I'd suggest you auto load it from within your autoload.php.

Also, you should not be access $_SESSION directly, you should be accessing it like this:

Code:
$this->session->set_userdata('key, 'value');

$data = $this->session->userdata('key');

This has the added advantage that if the specified key is not set, it returns FALSE, so you don't need to mess with isset().

Can you confirm what field names your 'members' table has? I'm wondering if it's not username, but user_name instead.
#16

[eluser]learning_php[/eluser]
Hi,

i have look at the database table and it is username, i have also added the session to the autoload but still get the same error:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: ID

Filename: models/MAdmins.php

Line Number: 17

this is a test
row_array1

here is my current code:

model:
Code:
<?PHP
    class MAdmins extends Model{
        
        function MAdmins(){
            
            parent::Model();
        }
        
        function verifyUser($u,$pw){
            $this->db->select('id,username');
            $this->db->where('username',$u);
            $this->db->where('password',$pw);
            
            $Q = $this->db->get('members');
            if ($Q->num_rows()>0){
                $row = $Q->row_array();
                $_SESSION['userid'] = $row['ID'];
                $_SESSION['username'] = $row['username'];
            }else{
                $this->sesson->set_flashdata('error','you have enter the wrong details');
            }
        }
    }
?>

controller:
Code:
<?PHP

class gallery extends Controller {
    
        
    function gallery()
    {
    session_start();
    parent::Controller();
    $this->load->database();
    $this->load->helper(array('url', 'form', 'date', 'cookie'));
    $this->load->library(array('form_validation', 'upload', 'Erkanaauth', 'session'));
    
    }
    
    function index(){
        $this->load->view('gallery_view');
    }
    function verify(){
        if ($this->input->post('username')){
            $u = $this->input->post('username');
            $pw = $this->input->post('password');
            
            $this->MAdmins->verifyUser($u,$pw);
            
            if ($_SESSION['userid']>0){
                redirect('Homepage');
            }
            $this->load->view('test_view');
        }
    }
}
?>

form:
Code:
<?= form_open('gallery/verify') ?>
  Username: <input type="text" name="username" id="username" value="" Autocomplete="off" /><br />
  <br />
  Password: &lt;input type="password" name="password" id="password" value="" /&gt;&lt;br />
  &lt;input type="submit" value="Login" /&gt;
&lt;?=form_close() ?&gt;
#17

[eluser]learning_php[/eluser]
rewritten form:
Code:
&lt;?PHP
                    $udata = array('name'=>'username','id'=>'u','size'=>15);
                    $pdata = array('name'=>'password','id'=>'p','size'=>15);
                    
                    echo form_open('gallery/verify');
                    echo "<P><label for = 'u'>username</label><br />";
                    echo form_input($udata)."</P>";
                    echo "<P><label for ='p'>password</label><br />";
                    echo form_password($pdata)."</P>";
                    echo form_submit('submit','login');
                    echo form_close();
                    ?&gt;
#18

[eluser]learning_php[/eluser]
Hi,

I have just removedid the id from the model and it seems to work but i do have a id in my table that is the PK?

Code:
&lt;?PHP
    class MAdmins extends Model{
        
        function MAdmins(){
            
            parent::Model();
        }
        
        function verifyUser($u,$pw){
            $this->db->select('username');
            $this->db->where('username',$u);
            $this->db->where('password',$pw);
            
            $Q = $this->db->get('members');
            if ($Q->num_rows()>0){
                $row = $Q->row_array();
                //$_SESSION['userid'] = $row['ID'];
                $_SESSION['username'] = $row['username'];
            }else{
                $this->sesson->set_flashdata('error','you have enter the wrong details');
            }
        }
    }
?&gt;


Also i add this to the routes.php to change the url but it does not work
Code:
$route['images'] = "gallery/verify";




Theme © iAndrew 2016 - Forum software by © MyBB