I recently tried to implement wiredesignz hmvc modular extension for Code igniter 2.2.1 found at https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/ I followed the instructions in the overview given to install the extension.
My database dump is below:
CREATE TABLE IF NOT EXISTS `admin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(250) NOT NULL,
`passwd` varchar(50) NOT NULL,
`type` enum('super','sub') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
--
-- Dumping data for table `admin`
--
INSERT INTO `admin` (`id`, `email`, `passwd`, `type`) VALUES
(1, 'deb.pratyush@gmail.com', 'd84c095fc9614ddd8d6cad216956ba11', 'super');
-- --------------------------------------------------------
--
-- Table structure for table `cms`
--
CREATE TABLE IF NOT EXISTS `cms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(250) NOT NULL,
`nav` varchar(20) NOT NULL,
`slug` varchar(300) NOT NULL,
`description` varchar(200) NOT NULL,
`keywords` varchar(160) NOT NULL,
`content` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'user id',
`fname` varchar(50) NOT NULL,
`lname` varchar(50) NOT NULL,
`email` varchar(250) NOT NULL,
`addr1` varchar(250) NOT NULL,
`addr2` varchar(250) NOT NULL,
`regdate` date NOT NULL,
`country` varchar(250) NOT NULL,
`pwd` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
I am using a model for authentication in the admin module
application/modules/admin/models/admin_model.php having
class name Admin_model. code for it is
class Admin_model extends CI_Model{
function __construct()
{
parent::__construct();
$this->load->database();
}
function auth_admin($email, $passwd)
{
echo $email.' '.$passwd;
$sql ="SELECT `id`, `email`, `type` FROM admin WHERE email='$email' AND passwd = MD5('$passwd')";
$res=$this->db->query($sql);
echo " res=<pre>".print_r($res, 1)."</pre>";
}
}
Admin controller is at application/modules/admin/controllers/admin.php having class name Admin. code is below:
class Admin extends MX_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('cms/cms_model');
$this->load->model('admin_model');
$this->load->library('session');
}
public function index()
{
$this->load->view('admin_header');
$this->load->view('admin_login');
$this->load->view('admin_footer');
if(!empty($this->input->post('admin_login')))
{
$email = $this->input->post('log');
$passwd = $this->input->post('pwd');
$auth_res = $this->admin_model->auth_admin($email, $passwd);
//print_r($auth_res);
if(!empty($auth_res))
{
}
}
}
}
Note that database library is autoloaded in application/config/autoload.php. Same for the url helper.
The output i am getting is below:
deb.pratyush@gmail.com pratyush res=
CI_DB_mysql_result Object
(
[conn_id] => Resource id #38
[result_id] => Resource id #47
[result_array] => Array
(
)
[result_object] => Array
(
)
[custom_result_object] => Array
(
)
[current_row] => 0
[num_rows] => 1
[row_data] =>
)
So, the debugging gives an empty result set despite the fact that user input sent through the login form is deb.pratyush@gmail.com as the email and pratyush as password (password is MD5 hashed in users table).
I have even tried hardcoding the values 'deb.pratyush@gmail.com' and 'pratyush' as email and password columns respectively but no luck.
I have been stuck for a lot of time with this. Can anyone please help?
If you are using codeignator the use codeignator standered of query
Read Manual CI QUERY
$this->db->where('email', $email);
$this->db->where('passwd', md5($passwd));
$query = $this->db->get('admin');
if (!$this->db->_error_message()) {
if ($query->num_rows() > 1) {
foreach ($query->result() as $row) {
print_r($row);
}
} else {
echo "error";
}
}