Last active
December 21, 2015 05:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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