Need Help in Login Script |
[eluser]Anes P.A[/eluser]
Hello pals, Previously I ask about Login Script Doubt. I create a sample program But in that I need to check "Blank Validation" for username and password. But it's not Working . Except that all other Fine . I attach my Code ALONG with this mail , pls look it and advise me how it can do ? I Try the CI validation class for same purpose , But I got some errors not any Result ... Pls help me I am waiting Your Reply ... My code is Given below... View --->loginpage.php ----------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Basic Login Page</title> [removed] function checkFill() { var user = docuemnt.getElementById('userName'); var pass = document.getElementById('password'); alert("dsfdfsdfsd"); if(trim(user.value)=="") { alert("Please Enter UserName"); return false; } else { return false; } } [removed] <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <link href="<?php echo base_url(); ?>csslogin/style.css" rel="stylesheet" type="text/css" /> <form method="post" action="login/doAction"> <div class="regform"> <div class="user_hd"> <div align="center">User Login</div> </div> <div class="user_ff1" id="TEST" align="center"></div> <div class="user_ff1" id="PPass" style="display:none;" align="center">Your Payment is Over. Like to pay ? <a href="renewal.php">Click Here </a></div> <div class="user"> <div class="username">Username :</div> <div class="textbox"><input name="userName" id="userName" type="text" class="search_bg" /> </div> <div class="user"> <div class="username">Password :</div> <div class="textbox"><input name="password" type="password" id="password" class="search_bg" /> </div> <div class="user_sub" style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#990033;"> <br /> <div align="center"> <input type="submit" value="Login"/> <a href="registration.php" class="register">Register </a> </div> </div> </div> </form> </body> </html> Controller ---- login.php --------------------------------------------- <?php class Login extends Controller { function Login() { parent::Controller(); //load library $this->load->library(array('validation','session')); // load helper $this->load->helper('url'); // load model $this->load->model('loginModel','',TRUE); //$dd = $this->loginModel->get_users('aness','anes'); //print_r($dd); } function index() { // set validation properties $this->_set_fields(); $this->_set_rules(); $this->load->view('loginpage'); } function doAction() { // run validation /*if ($this->validation->run() == FALSE){ $this->load->view('loginpage'); }else{*/ $dd = $this->loginModel->get_users(); if($dd==1) { echo "sucees"; } else { echo "Fail"; } } // } // validation fields function _set_fields(){ $fields['userName'] = 'userName'; $fields['password'] = 'password'; $this->validation->set_fields($fields); } // validation rules function _set_rules(){ $rules['userName'] = 'trim|required'; $rules['password'] = 'trim|required'; $this->validation->set_rules($rules); $this->validation->set_message('required', '* required'); $this->validation->set_message('isset', '* required'); $this->validation->set_error_delimiters('<p class="error">', '</p>'); } } ?> Model ---- loginModel.php -------------------------------------- <?php class LoginModel extends Model { function LoginModel(){ parent::Model(); } function get_users() { $this->load->database(); $user = $this->input->xss_clean($this->input->post('userName')); $pass = $this->input->xss_clean($this->input->post('password')); $this->db->select('username'); $this->db->from('users'); $this->db->where('username',$user); $this->db->where('password',$pass); $query = $this->db->get(); //return $query->row(); return $query->num_rows(); //return "sdsasdss"; } } ?> my Db table data is : CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `username` varchar(64) NOT NULL, `password` varchar(64) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `users` -- INSERT INTO `users` (`id`, `username`, `password`) VALUES (1, 'anes', 'anes');
[eluser]pistolPete[/eluser]
Please use [ code ] tags! Quote:But in that I need to check “Blank Validation” for username and password. But it’s not Working. What do you mean by “Blank Validation”? What isn't working? What do you expect, what do you get? Why do you use the deprecated Validation class? I'd suggest having a look at the renewed Form_validation class: http://ellislab.com/codeigniter/user-gui...ation.html
[eluser]Mat-Moo[/eluser]
I think your over complicating it ![]() http://ellislab.com/codeigniter/user-gui...ation.html but in the success section, call your databasemodel like Code: if $this->loginModel->check_user(set_value('username'),set_value('password')) redirect('user/logedin'); Code: function check_user($name,$password) However after all that blurb, there are quite a few AUTH systems in CI that you can put in with very little effort.... however nothing like learning the basics to learn CI ![]() Hope this helps
[eluser]Anes P.A[/eluser]
Hello Friends, According to your suggestion I use class form_validation instead of Deprecated validation class and Got the solution. Thanks for Your Good mind. Bye Anes |
Welcome Guest, Not a member yet? Register Sign In |