/src/owncms/Register/Register.php
PHP | 63 lines | 48 code | 12 blank | 3 comment | 4 complexity | f788cdb4138e8dfe0e397c139eac1343 MD5 | raw file
- <?php
- namespace App\owncms\Register;
- use PDO;
- class Register {
- public $id = '';
- public $username = '';
- public $email = '';
- public $password = '';
- public $db = '';
-
- public function __construct(){
- try{
- $this->db=new PDO('mysql:host=localhost;dbname=owncms',"root","");
- }
- catch(PDOException $e){
- echo $e->getMessage();
- }
- }
- public function prepare($data = '') {
- // echo "<pre>";
- // print_r($data);
- // die();
- if (array_key_exists('id', $data)) {
- $this->id = $data['id'];
- }
- if (array_key_exists('username', $data)) {
- $this->username = $data['username'];
- }
- if (array_key_exists('email', $data)) {
- $this->email = $data['email'];
- }
- if (array_key_exists('password', $data)) {
- $this->password = $data['password'];
- }
- }
- public function signUp(){
- $this->uniqueid= uniqid();
- $stmt="insert into users (id,unique_id,username,password,email) values (:id,:unique_id,:username,:password,:email)";
- $q=$this->db->prepare($stmt);
- $result=$q->execute(array(':id'=>NULL,':unique_id'=>$this->uniqueid,':username'=> $this->username,':password'=> $this->password,':email'=> $this->email));
-
- }
-
- public function lastid(){
- $this->user_id= $this->db->lastInsertId();
- $stmt="insert into profiles (id,user_id) values (:id,:user_id)";
- $stmt2="insert into articles (id,users_id) values (:id,:users_id)";
- $q= $this->db->prepare($stmt);
- $result=$q->execute(array(':id'=>NULL,':user_id'=>$this->user_id));
- $q2= $this->db->prepare($stmt2);
- $result=$q2->execute(array(':id'=>NULL,':users_id'=>$this->user_id));
- header('Location:../../../index.php');
- }
- }