Blame view

htdocs/documents/registerAction.php 1.02 KB
c10d2abc   rcavalie   ajout fichiers se...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  <?php
  session_start();
  if($_SESSION['name']){
  }else header('Location: index.php');
  require_once 'include/DB_Functions.php';
  $db = new DB_Functions();
  
  if (isset($_POST['name'])&& isset($_POST['username']) && isset($_POST['password'])) {
  
      // receiving the post params
      $name = $_POST['name'];
      $username = $_POST['username'];
      $password = $_POST['password'];
  
      // check if user is already existed with the same login
      if ($db->isUserExisted($username)) {
          // user already existed
          die ("User already existed with " . $username);
         
      } else {
          // create a new user
          $user = $db->storeUser($name, $username, $password);
          if ($user) {
              // user stored successfully
               echo "User saved!" ."<p>". "<a href='workArea.php'>Click here to continue</a>";
          } else {
              // user failed to store
              die("Unknown error occurred in registration!");
          }
      }
  } else {
      
      die ("Required parameters (name, username or password) is missing!");
  }
  ?>