Advertisement
Guest User

Something Something Boolean Error

a guest
May 15th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. <?php
  2.  
  3. require_once "../config/config.php";
  4.  
  5. class DevSystem
  6. {
  7.  
  8.     public static function addStudent($conn, $POST) {
  9.         $stno = $POST["stno"];
  10.         $status = $POST["status"];
  11.         $sYear = $POST["sYear"];
  12.         $session = $POST["session"];
  13.         $lastname = $POST["lastname"];
  14.         $firstname = $POST["firstname"];
  15.         $middlename = $POST["middlename"];
  16.         $birthdate = $POST["birthdate"];
  17.         $sex = $POST["sex"];
  18.         $username = $POST["username"];
  19.  
  20.         // Password generation
  21.         $password_hash = password_hash($firstname, PASSWORD_BCRYPT);
  22.         $gen_exp = explode("$",$password_hash);
  23.         $gen_split = str_split($gen_exp[3], 6);
  24.  
  25.         // Replacement of non-alphanumeric characters
  26.         $rand_int1 = rand(0, 9);
  27.         $rep1 = str_replace(".", $rand_int1, $gen_split[3]);
  28.         $rand_int2 = rand(0, 9);
  29.         $rep2 = str_replace("/", $rand_int2, $rep1);
  30.  
  31.         // Hashing for DB
  32.         $final_hash = password_hash($rep2, PASSWORD_BCRYPT);
  33.  
  34.         $stmt = $conn->db->prepare("INSERT INTO students (stno, status, sYear, session, lastname, firstname, middlename, birthdate, sex, username, password)
  35.        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  36.  
  37.         $stmt->bind_param(
  38.             "sssssssssss",
  39.             $stno,
  40.             $status,
  41.             $sYear,
  42.             $session,
  43.             $lastname,
  44.             $firstname,
  45.             $middlename,
  46.             $birthdate,
  47.             $sex,
  48.             $username,
  49.             $final_hash
  50.         );
  51.  
  52.         $response = '';
  53.         $response .= $stmt->execute() ? 'Student added. Password: ' . $rep2 : $stmt->error;
  54.         if($stmt->error) {
  55.             return $response;
  56.         }
  57.         $stmt->close();
  58.         return $response;
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement