TheDeanVanGreunen

QASO

Aug 29th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <?php
  2.     // SQL Code
  3.     $query = "INSERT INTO customer (name, email, password, contact, contactPerson, address, status, nic) VALUES (:name, :email, :password, :contact, :contactPerson, :address, 'active', :nic)";
  4.  
  5.     // PDO Prepare.
  6.     $insertRecordStmt = $connect->prepare($query);
  7.  
  8.     // PDO Execute With SQL Injection Safe Method.
  9.     $result = $insertRecordStmt->execute([
  10.         'name' => $name,
  11.         'email' => $email,
  12.         'password' => $password,
  13.         'contact' => $contact,
  14.         'contactPerson' => $contactPerson,
  15.         'address' => $address,
  16.         'nic' => $nic,
  17.     ]);
  18.  
  19.  
  20.     // Check Result
  21.     if ($result) {
  22.         //Save Last Insert ID.
  23.         $newId = $insertRecordStmt->lastInsertId();
  24.        
  25.         // Original Code
  26.         $_SESSION['Reg_Id'] = $newId;
  27.         $_SESSION['Reg_Name'] = $name;
  28.         $_SESSION['Reg_Password'] = $password;
  29.         $_SESSION['Reg_Location'] = "Home";
  30.         $_SESSION['Reg_Type'] = "customer";
  31.        
  32.         // Always Echo your data at the end of your code.
  33.         echo json_encode(['status' => 'success', 'message' => 'account registered']);
  34. }
  35.  
  36. // Recommendation:
  37. //
  38. //      It is best pratice to store the password as a hash such as a **sha1** with salt and paper,
  39. //      such as:
  40. //          <?php $password_hash = hash('sha1', 'S@lT' . $password . 'P3pp3r'); ?>
  41. //
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment