PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/owncms/Register/Register.php

https://gitlab.com/phpcodeinfected/owncms
PHP | 63 lines | 48 code | 12 blank | 3 comment | 4 complexity | f788cdb4138e8dfe0e397c139eac1343 MD5 | raw file
  1. <?php
  2. namespace App\owncms\Register;
  3. use PDO;
  4. class Register {
  5. public $id = '';
  6. public $username = '';
  7. public $email = '';
  8. public $password = '';
  9. public $db = '';
  10. public function __construct(){
  11. try{
  12. $this->db=new PDO('mysql:host=localhost;dbname=owncms',"root","");
  13. }
  14. catch(PDOException $e){
  15. echo $e->getMessage();
  16. }
  17. }
  18. public function prepare($data = '') {
  19. // echo "<pre>";
  20. // print_r($data);
  21. // die();
  22. if (array_key_exists('id', $data)) {
  23. $this->id = $data['id'];
  24. }
  25. if (array_key_exists('username', $data)) {
  26. $this->username = $data['username'];
  27. }
  28. if (array_key_exists('email', $data)) {
  29. $this->email = $data['email'];
  30. }
  31. if (array_key_exists('password', $data)) {
  32. $this->password = $data['password'];
  33. }
  34. }
  35. public function signUp(){
  36. $this->uniqueid= uniqid();
  37. $stmt="insert into users (id,unique_id,username,password,email) values (:id,:unique_id,:username,:password,:email)";
  38. $q=$this->db->prepare($stmt);
  39. $result=$q->execute(array(':id'=>NULL,':unique_id'=>$this->uniqueid,':username'=> $this->username,':password'=> $this->password,':email'=> $this->email));
  40. }
  41. public function lastid(){
  42. $this->user_id= $this->db->lastInsertId();
  43. $stmt="insert into profiles (id,user_id) values (:id,:user_id)";
  44. $stmt2="insert into articles (id,users_id) values (:id,:users_id)";
  45. $q= $this->db->prepare($stmt);
  46. $result=$q->execute(array(':id'=>NULL,':user_id'=>$this->user_id));
  47. $q2= $this->db->prepare($stmt2);
  48. $result=$q2->execute(array(':id'=>NULL,':users_id'=>$this->user_id));
  49. header('Location:../../../index.php');
  50. }
  51. }