• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
user login error

#1
[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;

#2
[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

#3
[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

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

#5
[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.

#6
[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>

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

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

#9
[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())

#10
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.