CodeIgniter Forums
user login error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: user login error (/thread-18069.html)

Pages: 1 2


user login error - El Forum - 04-24-2009

[eluser]learning_php[/eluser]
Hi,

i am trying to create a user login and but when i click the login button nothing happens? I have the following model,controller and form:

model:
Code:
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->session->set_flashdata('error','sorry, your username or password is incorrect!');
        }
    }
    
    
}

controller:
Code:
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('gallery','refresh');
                }
            }
            $this->load->view('test_view');
            
        }

form:

Code:
<?PHP
                    if($this->session->flashdata('error')){
                        echo "<div class = message>";
                        echo $this->session->flashdata('error');
                        echo "</div>";
                    }
                    ?&gt;
                    &lt;?PHP
                    $udata = array('name'=>'username','id'=>'u');
                    $pdata = array('name'=>'password','id'=>'p');
                    
                     form_open("homepage/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;



user login error - El Forum - 04-24-2009

[eluser]Zeeshan Rasool[/eluser]
Well i was looking that what can be the issue in this small module...!!

Dear you have missed the " echo " in open form line.

Code:
form_open("homepage/verify");

TO
Code:
echo form_open("homepage/verify");

Keep going...
Cheers


user login error - El Forum - 04-24-2009

[eluser]learning_php[/eluser]
Hi,

I will get there slowly mind you!

it know give me the following error:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: username

Filename: models/MAdmins.php

Line Number: 18
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\wedding-site\system\libraries\Exceptions.php:164)

Filename: helpers/url_helper.php

Line Number: 539



user login error - El Forum - 04-24-2009

[eluser]Dam1an[/eluser]
Well the redirect isn't working as you've already sent data to the browser (it could just be white space)


user login error - El Forum - 04-24-2009

[eluser]TheFuzzy0ne[/eluser]
The output was started by Exceptions.php, which suggests to me that your code is causing an exception to be thrown. Check the generated HTML source code from within your browser, and all will become clear.


user login error - El Forum - 04-24-2009

[eluser]learning_php[/eluser]
Hi,

this is the code from the browser but i still do not see the error:
Code:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  username</p>
<p>Filename: models/MAdmins.php</p>
<p>Line Number: 18</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\wedding-site\system\libraries\Exceptions.php:164)</p>
<p>Filename: helpers/url_helper.php</p>
<p>Line Number: 541</p>

</div>



user login error - El Forum - 04-24-2009

[eluser]Dam1an[/eluser]
What do you get when you call print_r on the row array?


user login error - El Forum - 04-24-2009

[eluser]learning_php[/eluser]
I did a print_r in the view and i did not get anything?


user login error - El Forum - 04-24-2009

[eluser]Dam1an[/eluser]
Now that is strange... so you're getting a result, but its an empty row?
See if it makes any difference using an object (row() instead of row_array())


user login error - El Forum - 04-24-2009

[eluser]learning_php[/eluser]
sorry my mistake I was looking at the wrong thing it prints this:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: _SESSION

Filename: controllers/homepage.php

Line Number: 75

row_array1