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