php - Can't fix error using codeIgniter -
I'm just new using Codeigner and I wanted to create a simple login with sign up and session.
This is my code ...
& lt ;? Php if (define ('basepath')) exit ('no direct script entry is allowed'); Class login verification expands CI_Controller {function __construct () {parent :: __ construct (); $ This- & gt; Load-> Model ('userModel', '', TRUE); } Function index () {$ this- & gt; Load-> Library ('form_validation'); $ This- & gt; Form_validation- & gt; Set_rules ('username', 'username', 'trim | required'); $ This- & gt; Form_validation- & gt; Set_reales ('password', 'password', 'trim | required | callback_ath_database'); If ($ this-> form_validation-> Run () == FALSE) {$ this-> Load-> View ('login_view'); } Else {redirect ('home', 'refresh'); }} Make this_database ($ password) work {$ username = $ this- & gt; Input-> Post ('username'); $ Result = $ it- & gt; User- & gt; Login ($ username, $ password); If ($ result) {$ sess_array = array (); Foreign currency ($ result as $ line) {$ sess_array = array ('id' =>; $ row-> ID, 'username' = & gt; $ row- & gt; username); $ This- & gt; Session-> Set_userdata (login_en, $ sess_array); } Return TRUE; } Other {$ this- & gt; Form_validation- & gt; Set_smege (this database, 'invalid user name or password'); return false; }}}? & Gt;
I do not know why I still got the error in trying to run this program.
If you are calling the DB query on the callback, try part of your method after the verification process, . Also check that you have already added session library. Also try my full code except syntax errors: -
& lt ;? Php if (define ('BASEPATH')) exit ('no direct script entry is allowed'); Class login verification expands CI_Controller {function __construct () {parent :: __ construct (); $ This- & gt; Load-> Model ('userModel', 'user'); } Function index () {$ this- & gt; Load-> Library ('form_validation'); $ This- & gt; Form_validation- & gt; Set_rules ('username', 'username', 'trim | required'); $ This- & gt; Form_validation- & gt; Set_rules ('password', 'password', 'trim | required'); If ($ this-> form_validation-> Run () == FALSE) {$ this-> Load-> View ('login_view'); } And {$ username = $ this- & gt; Input-> Post ('username'); $ Password = $ this- & gt; Input-> Post ('password'); $ Result = $ it- & gt; User- & gt; Login ($ username, $ password); If ($ result) {$ sess_array = array (); Foreign currency ($ result as $ line) {$ sess_array = array ('id' =>; $ row-> ID, 'username' = & gt; $ row- & gt; username); $ This- & gt; Session-> Set_userdata ('login', $ sess_array); } Redirect ('Home', 'Refresh'); } And {$ this- & gt; Form_validation- & gt; Set_message ('this_database', 'invalid user name or password'); Redirected ('home', 'refresh'); }}}}? & Gt;
Comments
Post a Comment