add_post.php (1091B) download
1<?php
2function add_user(string $pwd_key){
3 $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "panda");
4 $u = $db->get(Model\User::class);
5
6 $post_arr = Utils::post_to_array();
7 $missing_fields = Utils::missing_fields($post_arr , $u->not_nullable);
8
9 if(sizeof($missing_fields) > 0){
10 foreach($missing_fields as $key => $data){
11 if($post_arr[$key] == "")
12 $key .= "_error";
13 $post_arr[$key] = $data;
14 }
15 return $post_arr;
16 }
17
18 if($u->load($post_arr[$u->get_primary()])){
19 return ["msg" => "<p style=\"color:red;\">this email address is already taken: {$post_arr[$u->get_primary()]} </p>"];
20 }else{
21 if($post_arr[$pwd_key]){
22 $post_arr[$pwd_key] = password_hash($post_arr[$pwd_key], PASSWORD_DEFAULT);
23 }
24 foreach($u->column_names as $col){
25 if($post_arr[$col] != ""){
26 $u->$col = $post_arr[$col];
27 }
28 }
29 if($u->add())
30 return ["msg" => "<p style=\"color:green;\">succes</p>"];
31 else
32 return ["msg" => "<p style=\"color:red;\">could not add user to database</p>"];
33 }
34}
35
36
37