codeigniter- on change password display change password successful - php

My code so far is working and changing the user password. I would now like to display the user that their password was changed successfully else say try again but i cant make it happen. Any help would be appreciated, thanks.
Here is the controller:
public function change_password($arg = "admin")
{
if(isset($_POST['data']) && !empty($_POST['data']))
{
$this->load->library('form_validation');
$this->form_validation->set_rules('data[oldpassword]', 'old password', 'required');
$this->form_validation->set_rules('data[password]', 'password', 'trim|required');
$this->form_validation->set_rules('data[passconf]', 'password Confirmation', 'trim|required|md5|matches[data[password]]');
if ($this->form_validation->run() == FALSE)
{
$data['requestee'] = $arg;
$this->load->view('change_password', $data);
}
else
{
$data = $_POST['data'];
array_pop($data);
$data['requestee'] = $arg;
$data['email'] = $this->session->userdata('email');
//print_r($data); exit;
if($data['requestee'] == "admin")
{
$this->load->model('login_model');
if($this->login_model->updatepassword($data))
{
redirect('/admin/show', 'refresh');
}
else
{
redirect('login/change_password/');
}
}
elseif($data['requestee'] == "org")
{
$this->load->model('login_model');
if($this->login_model->updatepassword($data))
{
redirect('/organizer/show', 'refresh');
}
else
{
redirect('login/change_password/org');
}
}
else
{
echo "could not change password";
}
}
}
else
{
$data = array('requestee' => $arg);
$this->load->view('change_password', $data);
}
}
Here is the view:
<form action="<?php echo site_url('login/change_password'); ?>" class="login-wrapper" method="post">
<div class="header">
<div class="row-fluid">
<div class="span12">
<h3>Change password<img src="<?php echo asset_url();?>img/logo1.png" alt="Logo" class="pull-right"></h3>
<p>Fill out the form below to change your password.</p>
</div>
</div>
</div>
<div class="content">
<div class="row-fluid">
<div class="span12">
<input class="input span12 password" id="" name="data[oldpassword]" placeholder="Old password" required="required" type="password" value="<?php echo set_value('oldpassword'); ?>">
</div>
</div>
<div class="row-fluid">
<div class="span12">
<input class="input span12 password" id="" name="data[password]" placeholder="New password" required="required" type="password" value="<?php echo set_value('password'); ?>">
</div>
</div>
<div class="row-fluid">
<div class="span12">
<input class="input span12 password" id="" name="data[passconf]" placeholder="Confirm new password" required="required" type="password" value="<?php echo set_value('passconf'); ?>" >
</div>
</div>
</div>
<div class="actions">
<input class="btn btn-danger" name="change_password" type="submit" value="Change" >
<div class="clearfix"></div>
</div>
</form>

It appears that after changing the users password, you are using a redirect to return the user to another page.
In your controller, just before doing the redirect, You can use CodeIgniters session data to set a message in flashdata like so:
$this->session->set_flashdata('message', 'Your Password Was Successfully Changed');
or
$this->session->set_flashdata('message', 'Your Password Was Not Changed');
Then in your view, you can add:
<?php echo $this->session->flashdata('message'); ?>
Please note that in order for this to work, if you have not done so already, you will need to either manually load the session library on every page where it is used or add it to your autoload.php file.

Related

user_validation function is not invoked in Home controller in codeigniter

I need to validate a user form, which I am trying to submit after taking the input in view named as 'home.php', where I have specified the base_url('Home/user_validation').
With Home is name of the controller and user_validation is the method name. I tried to figure out the issue but I could not understand why not any other function is being invoked apart from index function in Home controller. Please help me in this case.
Controller Home.php
public function user_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if ($this->form_validation->run() == FALSE) {
$this->session->set_flashdata('message', 'Invalid username and password.');
redirect('home');
}
else {
$user_name123 = $this->input->post('username');
$teacher = $this->input->post('remember');
if ($user_name123 == 'admin') {
$query = $this->login_model->validate();
echo("Logged in");
}
}
}
Model login_model.php
function validate()
{
$this->db->where('admin_username', $this->input->post('username'));
$this->db->where('admin_password', $this->input->post('password'));
$this->db->where('active_status', 'Yes');
$query = $this->db->get('cis_tbl_admin');
if ($query->num_rows() == 1) {
return true;
}
else {
return false;
}
}
View home.php
<form action="<?php echo base_url('Home/user_validation') ?>" method="post" id="instantform">
<fieldset>
<div class="input-prepend" title="Username" data-rel="tooltip">
<span class="add-on"><i class="icon-user"></i></span>
<input autofocus class="input-large span10"
name="username" id="username" type="text"
placeholder="user name"/>
</div>
<div class="clearfix"></div>
<div class="input-prepend" title="Password" data-rel="tooltip">
<span class="add-on"><i class="icon-lock"></i></span>
<input class="input-large span10" name="password"
id="password" type="password"
placeholder="password" autocomplete="off"/>
</div>
<div class="clearfix"></div>
<div class="input-prepend">
<label class="remember" for="remember">
<input type="checkbox" name="remember" id="remember"
value="teacher"/>Teacher Login</label>
</div>
<div class="clearfix"></div>
<p class="center span5">
<button type="submit" name="submit" id="submit" class="btn btn-primary">Login</button>
<br/><br/>
<!--<a class="ajax-link" href="<?php echo base_url(); ?>parent_info/get_students_info"> <span class="hidden-tablet">Parent Login</span></a>-->
</p>
</fieldset>
<input type="hidden" name="sys_date" id="sys_date" value="<?php echo $sys_date; ?>">
<input type="hidden" name="sys_time" id="sys_time" value="<?php echo $sys_time; ?>">
<input type="hidden" name="details" id="details" value="<?php echo $details; ?>">
</form>
Check your config routes file to be sure you call functions of the home controller:
$route['Home/(:any)'] = 'Home/$1';

I need to create a function which will check for old password and update the current one

I have already created a login and registration system in my website. I have a table in my database where all the user information is stored called 'users'.I searched a lot but could not get much far.
My class
public function change_password()
{
$this->load->view('templates/header');
$this->load->view('registration/changepassword');
$this->load->view('templates/footer');
}
public function change()
{
$this->form_validation->set_rules('newpassword', 'New Password', 'required|matches[rpassword]');
$this->form_validation->set_rules('rpassword', 'Retype Password', 'required');
if ($this->form_validation->run() == FALSE) {
redirect('registration/change_password');
}else{
$query = $this->Login_Database->checkOldPass(sha1($this->input->post('oldpassword')));
if($query){
$query = $this->Login_Database->saveNewPass(sha1($this->input->post('newpassword')));
if($query){
redirect('registration/change_password');
}else{
redirect('registration/change_password');
}
}
redirect('');
}
}
My model
// Insert registration data in database
public function checkOldPass($old_password)
{
$this->db->select('*');
$this->db->from('users');
$this->db->select('id');
$this->db->where('id', 'id');
$this->db->where('password', $this->input->post('oldpassword'));
$query = $this->db->get();
if ($query->num_rows > 0) {
return true;
} else {
$this->form_validation->set_message('checkOldPassword', 'wrong old password.');
return false;
}
}
public function saveNewPass($new_pass)
{
$data = array(
'password' => $new_pass
);
$this->db->where('id', 'id');
$this->db->update('users', $data);
return true;
}
}
My form
<h1><p class="text-center" style="font-family: 'Passion One',
cursive;">Change Password</p></h1>
<div>
<form class="form-horizontal" method="post"
action="<?php echo base_url() ?>Registration/change">
<fieldset>
<br>
<div class="form-group">
<label class="col-md-4 control-label" for="phone">Old
Password</label>
<div class="col-md-4">
<input id="oldpassword" name="oldpassword" type="password"
placeholder="Old Password"
class="form-control input-md"
required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="phone">New
Password</label>
<div class="col-md-4">
<input id="newpassword" name="newpassword" type="password"
placeholder="New Password"
class="form-control input-md"
required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="phone">Conform
Password</label>
<div class="col-md-4">
<input id="rpassword" name="rpassword" type="password"
placeholder="Retype Password"
class="form-control input-md"
required="">
</div>
</div>
<br>
<!-- Button (Double) -->
<div class="form-group">
<label class="col-md-4 control-label" for="save"></label>
<div class="col-md-8">
<button type="submit" class="btn btn-success">Save</button>
<a id="cancel" name="cancel" class="btn btn-danger" href="<?
php echo base_url(); ?>">
Cancel</a><br><br>
</div>
<br><br><br>
</fieldset>
</form>
</div>
My class is inside a class called Registration.Any help would be much appreciated. Also the name of my model is 'Login_Database.php' and the name of my form is 'changepassword.php'
Please use below code in controller and your model. if you have any problem please reply me.
// controller function
public function change(){
if ($this->form_validation->run('update_password') == True)
{
$old_password = sha1($_POST['oldpassword']);
unset($_POST['oldpassword']);
$post = $this->input->post();
$status = $this->model_name->check_old_password($old_password, $user_id); //check old password
if($status==true){
if($_POST['newpassword']==$_POST['rpassword']){
if($this->model_name->update_password($post, $user_id)){
$this->session->set_flashdata('message_success', "Password update successully.");
redirect('registration/change_password');
}else{
$this->session->set_flashdata('article_failed', "Password not update successully.");
redirect('registration/change_password');
}
}else{
$this->session->set_flashdata('article_failed', "Sorry your new password and confirm password does not matched.");
redirect('registration/change_password');
}
}
}else{
$this->session->set_flashdata('article_failed', "Sorry your old password is wrong.");
redirect('registration/change_password');
}
}
// model function
public function check_old_password($old_password, $user_id){
$query = $this->db->select('id')
->from('users')
->where(['id'=>$user_id, 'password'=>$old_password])
->get()
->row();
if($query>0){
return TURE;
}else{
return FALSE;
}
}
public function update_password($post, $user_id){
$password = sh1($post['newpassword']);
return $this->db->where('id', $user_id)
->update('users', ['password'=>$password]);
}

how to use required in form_validation in ci?

Hi when I use required in my rules in ci form_validation, I know the value of this required input post and don't show any message .but this if ($this->form_validation->run()) is always false.
thanks for your help.
my view:
<form>
<div class="row">
<div class="form-group">
<div class="col-md-2"><label>Name</label></div>
<div class="col-md-10 col-md-pull-1">
<input name="Name" class="form-control" id="Name"
value="<?php echo set_value('Name')?>"
autocomplete="off"></input>
<?php echo form_error('Name'); ?>
</div>
</div>
</div>
</form>
my controller:
public function show_info()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('Name', 'Name', 'required');
$this->form_validation->set_message('required'," please enter %s");
if ($this->form_validation->run()== FALSE)
{
echo "false";
}
else redirect();
}
In your view file, you had wrote nmae except name
<div class="row">
<div class="form-group">
<div class="col-md-2"><label>Name</label></div>
<div class="col-md-10 col-md-pull-1">
<input name="Name" class="form-control" id="Name"
value="<?php echo set_value('Name')?>"
autocomplete="off"></input>
<?php echo form_error('Name'); ?>
</div>
</div>
</div>
correct it.
please load again view file after false form_validation
public function show_info()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('Name', 'Name', 'required');
$this->form_validation->set_message('required'," please enter %s");
if ($this->form_validation->run()== FALSE)
{
echo "false";
$this->load->view('view_file','',true);
}
else redirect();
}

Blank page after submit

I've been busy creating a login script, only problem is i get a blank page after submitting the login form. I'm using a Template System.
Some codes,
login.tpl:
<div class="container">
<form class="form-login" action="/customer/login/submit" method="post">
<h2 class="form-login-heading">$site_name Customer Panel</h2>
<div class="login-wrap">
<input type="text" name="loginusername" class="form-control" placeholder="Username" autofocus>
<input type="password" name="loginpassword" class="form-control" placeholder="Password">
<button class="btn btn-lg btn-login btn-block" type="submit" name="login">Log in</button>
<center>
<div class="registration">
Don't got an account yet?
<a class="" href="$site_url/customer/register">
Create an account
</a>
</div>
</center>
</div>
</form>
Submit.php:
<?php
if (!isset($_POST['loginusername'], $_POST['loginpassword']))
{
Site::Stop('/customer/login');
}
$Error = Users::Login($_POST['loginusername'], $_POST['loginpassword']);
if (isset($_SESSION['username']))
{
Site::Stop('/customer/dashboard');
}
$_SESSION['login_error'] = $Error;
Site::Stop('/customer/login');
?>
login.php:
$this->Define('LoginError', '');
if (isset($_SESSION['login_error']))
{
$errors = Array(
1 => 'This username does not exist.',
2 => 'Your password is incorrect.');
if ($_SESSION['login_error'] == 3)
{
$errors[3] = ' Your '.$_SESSION['ban']['bantype'].' is banned.
Reason: '.$_SESSION['ban']['reason'].'.
Your ban expires on: '.date('d-m-y H:i:s', $_SESSION['ban']['expire']);
unset($_SESSION['ban']);
}
$this->Define('LoginError', '<div class="well well-danger">'.$errors[$_SESSION['login_error']].'</div>');
unset($_SESSION['login_error']);
}
$this->LoadTpl('Login');
Maps.php
<?php
$this->Map('/customer/login', 'Login.php');
$this->Map('/customer/register', 'Register.php');
$this->Map('/customer/register/submit', 'RegSubmit.php');
if (Users::$Session === false)
{
$this->Map('/customer/login/submit', 'Submit.php');
}
else
{
$this->Map('/customer/logout', 'Logout.php');
}
?>
Make sure session has started with session_start() on top of php file.

Login code is not working on my code

This my model page where I make database connectivity. Registration from working fine but login form not working. Even don't show any message too. I not good in codeigniter. Please let me know where is wrong.
Below is my code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
}
public function index()
{
if($this->session->userdata('user_name')!="")
{
$this->welcome();
}
else
{
$data['title']= 'Home';
$this->load->view("index.php", $data);
}
}
function welcome()
{
$data['title']= 'Welcome';
$this->load->view('header_view',$data);
$this->load->view('welcome_view.php', $data);
$this->load->view('footer_view',$data);
}
public function login()
{
alert("gregrtg");
$email=$this->input->get('email');
$password=$this->input->get('password');
$result=$this->user_model->login($email,$password);
$data['title']= 'Register successfully!';
//if($result)
//$input = '/application/views/vendor-profile.php'; // you can't access view directly. call this view from a controller.
// echo json_encode(array("next_url"=>$input));
if($result) $this->load->view("vendor-profile.php",$data);
else $this->index();
}
function thank()
{
$this->user_model->add_user();
$data['title']= 'Register successfully!';
$this->load->view("index.php", $data);
}
public function registration()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('user_name', 'User Name', 'trim|required|min_length[4]|xss_clean|callback_check_user_ci');
$this->form_validation->set_rules('user_mobile','User Mobile','trim|required|min_lenght[10]|max_length[10]');
$this->form_validation->set_rules('email_address', 'Your Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$this->user_model->add_user();
$data['title']= 'Register successfully!';
$this->thank();
}
}
public function logout()
{
$newdata = array(
'user_id' =>'',
'user_name' =>'',
'user_email' => '',
'logged_in' => FALSE,
);
$this->session->unset_userdata($newdata);
$this->session->sess_destroy();
$this->index();
}
public function check_user_ci()
{
$usr=$this->input->post('user_name');
$result=$this->user_model->check_user_exist($usr);
if($result)
{
$this->form_validation->set_message('check_user', 'User Name already exit.');
return false;
}
else
{
return true;
}
}
public function check_user()
{
$usr=$this->input->post('name');
$result=$this->user_model->check_user_exist($usr);
if($result)
{
echo "false";
}
else{
echo "true";
}
}
}
?>
this is my controller file....
<!-- Modal Popup Sign Up and Login Start Here -->
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Sign Up / Login</h4>
</div>
<!-- Tab Start Here -->
<div role="tabpanel">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><span class="commom-icon signup"></span> Sign Up</li>
<li role="presentation"><span class="commom-icon login"></span> Log In</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="signup">
<?php echo validation_errors('<p class="error">'); ?>
<?php echo form_open("user/thank"); ?>
<div class="signUpForm">
<div class="form-group" id="title1">
<?php echo $title; ?>
</div>
</div>
<div class="signUpForm">
<div class="form-group">
<label for="inputText">Enter Name</label>
<input type="text" class="form-control" placeholder="Enter Name" id="user_name" name="user_name" value="<?php echo set_value('user_name'); ?>" /><div id="usr_verify" class="verify" style="display:none;"> Invalid User</div>
<div id="usr_verify1" class="verify" style="display:none;">User Field should not be empty!</div>
</div>
<div class="form-group">
<label for="inputText">Enter Mobile No.</label>
<input type="text" id="mobile_number" class="form-control" placeholder="Enter Mobile No." name="mobile_number" value="<?php echo set_value('mobile_number'); ?>" /><span id="mobile_verify" class="verify" style="display:none;">Invalid Mobile Number</span><span id="mobile_verify1" class="verify" style="display:none;"> Mobile number should not be Empty</span>
</div>
<div class="form-group">
<label for="inputText">Enter Email</label>
<input type="text" id="email_address" class="form-control" placeholder="Enter Mobile No." name="email_address" value="<?php echo set_value('email_address'); ?>" /><span id="email_verify" class="verify"style="display:none;">Invalid EmailID</span><span id="email_verify1" class="verify" style="display:none;"> EmailID should not be Empty</span>
</div>
<div class="form-group">
<label for="inputPassword">Password:</label>
<input type="password" id="password" class="form-control" placeholder="Enter Password" name="password" value="<?php echo set_value('password'); ?>" /><span id="password_verify" class="verify" style="display:none;">Password Should not be empty</span>
</div>
<div class="form-group">
<label for="inputPassword">Confirm Password:</label>
<input type="password" id="con_password" class="form-control" placeholder="Enter Confirm Password" name="con_password" value="<?php echo set_value('con_password'); ?>" /><span id="confrimpwd_verify" class="verify" style="display:none;">Confirm Password Should not be empty!</span>
<span id="confrimpwd_verify1" class="verify" style="display:none;">Confirm Password and password not matching!</span>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12" align="right">
<input type="button" id="formsubmit" class="greenButton" value="Submit" />
<!-- <button type="submit" class="btn btn-danger">Submit</button>-->
</div>
</div>
<?php echo form_close(); ?>
</div>
<div role="tabpanel" class="tab-pane" id="login">
<?php echo form_open("user/login");?>
<div class="loginForm">
<div class="form-group" id="myDiv">
<?php echo $title;?>
</div>
<div class="form-group">
<label for="exampleInputEmail1"> Email address</label>
<input type="email" class="form-control" id="useremail" placeholder="Enter email" value="<?php echo set_value('username'); ?>">
</div>
<div id="emailerror" style="display:none;">Email Field is required!</div>
<div class="form-group">
<label for="exampleInputPassword1"> Password</label>
<input type="password" class="form-control" id="userpassword" placeholder="Password" value="<?php echo set_value('userpassword'); ?>">
</div>
<div id="passworderror" style="display:none;">Password field is required!</div>
<div class="row">
<div class="col-xs-6 mb20 forgetBtn" align="left"> <span class="label label-warning cp">Forget Password ! ! !</span> </div>
<div class="col-xs-6" align="right">
<input type="button" class="btn btn-danger" id="check" value="Login">
</div>
</div>
</div>
<div id="div1"></div>
<?php echo form_close(); ?>
<form>
<div class="fgtForm hide">
<div class="form-group">
<label for="exampleInputEmail1"> Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" required>
</div>
<div class="row">
<div class="col-xs-6 mb20 backLoginBtn" align="left"> <span class="label label-warning cp">Back to Login</span> </div>
<div class="col-xs-6" align="right">
<input type="button" class="greenButton" value="Submit" onclick="validate()" />
<!--<button type="submit" class="btn btn-danger">Click To Process</button>-->
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Tab End Her -->
</div>
</div>
</div>
<!-- Modal Popup Sign Up and Login End Here -->
<script type="text/javascript">
$("#formsubmit").click(function(){
var oxmlHttpSend;
if($("#user_name").val().length == 0)
{
$("#usr_verify1").show();
}
var mobile=$("#mobile_number").val();
var phoneno = /^\d{10}$/;
if(mobile!="")
{
if(mobile.match(phoneno))
{
$("#mobile_verify").hide();
$("#mobile_verify1").hide();
}
else
{
$("#mobile_verify").show();
$("#mobile_verify1").hide();
}
}
else
{
$("#mobile_verify1").show();
$("#mobile_verify").hide();
}
var email = $("#email_address").val();
if(email!="")
{
var regex = /^([0-9a-zA-Z]([-_\\.]*[0-9a-zA-Z]+)*)#([0-9a-zA-Z]([-_\\.]*[0-9a-zA-Z]+)*)[\\.]([a-zA-Z]{2,9})$/;
if(!regex.test(email))
{
$("#email_verify").show();
$("#email_verify1").hide();
}
else{
$("#email_verify").hide();
}
}
else
{
$("#email_verify1").show();
$("#email_verify").hide();
}
var password=$("#password").val();
if(password=="")
{
$("#password_verify").show();
}
else
{
$("#password_verify").hide();
}
var con_password=$("#con_password").val();
if(con_password=="")
{
$("#confrimpwd_verify").show();
}
else
{
$("#confrimpwd_verify").hide();
}
if(password!=con_password)
{
$("#confrimpwd_verify1").show();
}
else
{
$("#confrimpwd_verify1").hide();
}
if(typeof XMLHttpRequest != "undefined")
{
oxmlHttpSend = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
oxmlHttpSend = new ActiveXObject("Microsoft.XMLHttp");
}
if(oxmlHttpSend == null)
{
alert("Browser does not support XML Http Request");
return;
}
var url = "<?php echo base_url();?>index.php/user/thank";
url += "?name=" + $("#user_name").val() + "&mobile=" + $("#mobile_number").val() +"&email=" + $("#email_address").val() +"&password=" + $("#password").val();
oxmlHttpSend.open("GET",url,true);
oxmlHttpSend.send(url);
});
</script>
<script >
$("#check").click(function()
{
var df1=$("#useremail").val();
var df2=$("#userpassword").val();
if(df1=="")
{
$("#emailerror").show();
$("#passworderror").hide();
}
if(df2=="")
{
$("#emailerror").hide();
$("#passworderror").show();
}
if(df1=="" && df2=="")
{
$("#emailerror").show();
$("#passworderror").show();
}
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
url="<?php echo base_url();?>index.php/user/login";
url+="?email= "+$("#useremail").val()+"&password= "+$("#userpassword").val();
xmlhttp.open("GET",url,true);
xmlhttp.send();
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
</script>
main view page where login form is not working
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
function login($email,$password)
{
$this->db->where("email",$email);
$this->db->where("password",$password);
$query=$this->db->get("user");
if($query->num_rows()>0)
{
foreach($query->result() as $rows)
{
//add all data to session
$newdata = array(
'user_id' => $rows->id,
'user_name' => $rows->username,
'user_mobile' => $rows->mobile,
'user_email' => $rows->email,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
return true;
}
return false;
}
public function add_user()
{
$this->db->where("email",$this->input->get('email'));
$query=$this->db->get("user");
if($query->num_rows()>0)
{
return true;
}
else
{
$data=array(
'username'=>$this->input->get('name'),
'mobile'=>$this->input->get('mobile'),
'email'=>$this->input->get('email'),
'password'=>md5($this->input->get('password'))
);
$this->db->where("username",$data['username']);
$query=$this->db->get("user");
$result=$this->db->insert('user',$data);
if($result->num_rows()>0)
{
return true;
}
else
{
if($query->num_rows()>0)
{
return true;
}
else
{
return false;
}
}
}
}
public function check_user_exist($usr)
{
$this->db->where("username",$usr);
$query=$this->db->get("user");
if($query->num_rows()>0)
{
return true;
}
else
{
return false;
}
}
}
?>
alert("gregrtg"); is a function for JavaScript and not for PHP.

Categories