Welcome Guest, Not a member yet? Register   Sign In
Model (verify username & password
#21

[eluser]psychoder[/eluser]
have you populated your database with sample data?
#22

[eluser]CodeIgniteMe[/eluser]
Can you display the error when you executed the query? Thanks
#23

[eluser]terry101[/eluser]
yup, now i get this in after i put a random username/password which doesnt match any in my database.


object(CI_DB_mysql_result)[17]
public 'conn_id' => resource(29, mysql link persistent)
public 'result_id' => resource(34, mysql result)
public 'result_array' =>
array
empty
public 'result_object' =>
array
empty
public 'custom_result_object' =>
array
empty
public 'current_row' => int 0
public 'num_rows' => int 0
public 'row_data' => null

( ! ) Fatal error: Call to undefined method CI_DB_mysql_result::num_row() in C:\wamp\www\logintest\application\models\loginmodel.php on line 13
Call Stack
# Time Memory Function Location
1 0.0006 700440 {main}( ) ..\index.php:0
2 0.0020 787536 require_once( 'C:\wamp\www\logintest\system\core\CodeIgniter.php' ) ..\index.php:201
3 0.0434 3852744 call_user_func_array ( ) ..\CodeIgniter.php:339
4 0.0434 3852824 Userlogin->login( ) ..\CodeIgniter.php:0
5 0.0515 4197440 Loginmodel->check_login( ) ..\userlogin.php:27
#24

[eluser]CodeIgniteMe[/eluser]
What is your Apache version? you PHP version?maybe you are running php 4 which doesn't support method chaining. hmm.. could you try
Code:
if($verifylogin->num_rows == 1) //removed the ()
#25

[eluser]terry101[/eluser]
my wamp server is 2.1 and my apache 2.2.17, that runs php 5.3 i believe
#26

[eluser]CodeIgniteMe[/eluser]
What happened when you tried the code above?
and comment the var_dump()
#27

[eluser]terry101[/eluser]
ok there progress i see that my else statement is comming up where the username and password is invalid but when i test a valid username and password i still get user name or password is invalid.

object(CI_DB_mysql_result)[17]
public 'conn_id' => resource(29, mysql link persistent)
public 'result_id' => resource(34, mysql result)
public 'result_array' =>
array
empty
public 'result_object' =>
array
empty
public 'custom_result_object' =>
array
empty
public 'current_row' => int 0
public 'num_rows' => int 0
public 'row_data' => null
A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_DB_mysql_result::$num_row

Filename: models/loginmodel.php

Line Number: 13

Username or password is invalid, try again

Line 13
Code:
if ($verifylogin->num_row == 1) {

MODEL
Code:
<?php

class Loginmodel extends CI_Model {
    
    function check_login ($username, $password) {
        $en_password = MD5($password);
        
        $this->load->database('blog');
        
        $checklogin = array('username' => $username, 'password' => $password);
        $verifylogin = $this->db->get_where('tbregister',$checklogin);
        var_dump($verifylogin);
        if ($verifylogin->num_row == 1) {
            
            return TRUE;
        }
        else {
            
            return FALSE;
        }
    }
}
#28

[eluser]CodeIgniteMe[/eluser]
Here are some of ways for me to debug these kind of errors
1. Enable the profiler
2. Copy the SQL generated from the active record
3. Test the SQL on PHPMyAdmin (if your database is MySQL and you have PHPMyAdmin Installed)
4. Try to check if you can really connect to the database using CodeIgniter, or check you database config files. I noticed that you manually connect to your database, check if autoinit is on
#29

[eluser]terry101[/eluser]
i use php myadmin, i'm sure it connects to the database since i have tried to insert data (registration forms.

how do i enable the profiler?


config auto load
$autoload['libraries'] = array('database');

database (database name is blog)

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'blog';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
#30

[eluser]CodeIgniteMe[/eluser]
If you have autoloaded the database, you might not need to manually load the database such as
Code:
$this->load->database();
and to enable profiler, you will just add
Code:
$this->output->enable_profiler(1); // 0 to disable or just remove it
in your method/function where you want to profile




Theme © iAndrew 2016 - Forum software by © MyBB