Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. <?php
  2. class Tabel extends CI_Model {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->dbforge();
  6. }
  7. function drop_table($table){
  8. $this->dbforge->drop_table($table);
  9. }
  10.  
  11. function add()
  12. {
  13. echo form_open('user');
  14. $email = array (
  15. 'name' => 'email',
  16. 'id' => 'email'
  17. );
  18. $username = array(
  19. 'name' => 'username',
  20. 'id' => 'username'
  21. );
  22. $password = array(
  23. 'name' => 'password',
  24. 'id' => 'password'
  25. );
  26.  
  27. echo "email : ". form_input($email). br();
  28. echo "Username : ". form_input($username). br();
  29. echo "Password : ". form_password($password). br();
  30.  
  31. echo form_submit('submit', 'Login');
  32. echo form_close();
  33. echo $msg;
  34. $format = 'DATE_W3C';
  35. $time = time();
  36. $date = standard_date($format, $time);
  37. $data = array
  38. (
  39. 'id' => '' ,
  40. 'imail' => $email ,
  41. 'username' => $username,
  42. 'password' => $password,
  43. 'is_active' => 1,
  44. 'last_login' => $date,
  45. );
  46. $this->db->insert('users', $data);
  47. }
  48. function edit()
  49. {
  50.  
  51. }
  52. function delete($id)
  53. {
  54. $this->db->delete('users', array('id' => $id));
  55. }
  56.  
  57. function create_table($table){
  58. $this->load->model('tabel');
  59. function create_table($table){
  60.  
  61. $fields = array
  62. (
  63. 'id' => array(
  64. 'type' => 'BIGINT',
  65. 'constraint' => 20,
  66. 'null' => FALSE,
  67. 'auto_increment' => TRUE
  68. ),
  69. 'email' => array(
  70. 'type' => 'VARCHAR',
  71. 'constraint' => '100',
  72. 'null' => FALSE
  73. ),
  74. 'username' => array(
  75. 'type' =>'VARCHAR',
  76. 'constraint' => '50',
  77. 'null' => FALSE
  78. ),
  79. 'password' => array(
  80. 'type' => 'VARCHAR',
  81. 'constraint' => '100',
  82. 'null' => FALSE,
  83. ),
  84. 'is_active' => array(
  85. 'type' => 'TINYINT',
  86. 'constraint' => '1',
  87. 'null' => FALSE,
  88. ),
  89. 'last_login' => array(
  90. 'type' => 'DATETIME',
  91. 'null' => FALSE,
  92. ),
  93. );
  94. $this->dbforge->add_field($fields);
  95. $this->dbforge->add_key('id', TRUE);
  96. $this->dbforge->create_table($table, TRUE);
  97. }
  98.  
  99. function first_insert(){
  100. $format = 'DATE_W3C';
  101. $time = time();
  102. $date = standard_date($format, $time);
  103. $email = "admin@admin.com";
  104. $username = "admin";
  105. $password = "admin";
  106. $data = array
  107. (
  108. 'id' => '' ,
  109. 'imail' => $email ,
  110. 'username' => $username,
  111. 'password' => $password,
  112. 'is_active' => 1,
  113. 'last_login' => $date,
  114. );
  115.  
  116. $this->db->insert('users', $data);
  117. }
  118.  
  119. function checklogin(){
  120. $username = $this->input->post('username');
  121. $password = $this->input->post('password');
  122. $table = 'users';
  123. $where = array('username' => $username, 'password' => $password);
  124. $this->db->select()->from($table)->where($where);
  125. $query = $this->db->get();
  126. return $query->num_rows();
  127. }
  128.  
  129. function update_date(){
  130. $username = $this->input->post('username');
  131. $password = $this->input->post('password');
  132. $format = 'DATE_W3C';
  133. $time = time();
  134. $date = standard_date($format, $time);
  135. $data = array(
  136. 'last_login' => $date
  137. );
  138. $where = array('username' => $username, 'password' => $password);
  139. $this->db->where($where);
  140. $this->db->update('users', $data);
  141. }
  142.  
  143. function get_last_ten_entries(){
  144. $query = $this->db->get('users', 10);
  145. return $query->result_array();
  146. }
  147. }
  148. }
  149. /* End of file tabel.php */
  150. /* Location: ./application/models/tabel.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement