Skip to content

Instantly share code, notes, and snippets.

@MichaelObi
Last active December 21, 2015 05:28
Show Gist options
  • Save MichaelObi/6256791 to your computer and use it in GitHub Desktop.
Save MichaelObi/6256791 to your computer and use it in GitHub Desktop.
Shows the signup function in users model to insert user data into database - CodeIndulge tutorial.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* implements signup and login of users */
class Users_model extends CI_Model {
//To implement user signup
public function signup_user($data){
$signup['email'] = trim(mysql_real_escape_string($data['email']));
$signup['fname'] = trim(mysql_real_escape_string($data['fname']));
$signup['lname'] = trim(mysql_real_escape_string($data['lname']));
$signup['phone'] = trim(mysql_real_escape_string($data['phone']));
$signup['password'] = md5($data['password']);
$signup['gcm_id'] = $data['gcmId'];
$exists = $this->userExists($signup['email']);
if($exists === FALSE){
$this->db->insert('users', $signup);
//select login data
$email = $signup['email'];
$password = $signup['password'];
$query = $this->db->query("SELECT * FROM users WHERE email = '$email' AND password = '$password'");
/*
* produce array out of query results
*/
$row = $query->row_array();
/*
* login is only correct if there's only one row selected
*/
if($query->num_rows() === 1){
return $row;
}
else {
return 0;
}
}
else{
return 1;
}
}
}
/* End of file users_model.php */
/* Location: ./application/models/users_model.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment