Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // SQL Code
- $query = "INSERT INTO customer (name, email, password, contact, contactPerson, address, status, nic) VALUES (:name, :email, :password, :contact, :contactPerson, :address, 'active', :nic)";
- // PDO Prepare.
- $insertRecordStmt = $connect->prepare($query);
- // PDO Execute With SQL Injection Safe Method.
- $result = $insertRecordStmt->execute([
- 'name' => $name,
- 'email' => $email,
- 'password' => $password,
- 'contact' => $contact,
- 'contactPerson' => $contactPerson,
- 'address' => $address,
- 'nic' => $nic,
- ]);
- // Check Result
- if ($result) {
- //Save Last Insert ID.
- $newId = $insertRecordStmt->lastInsertId();
- // Original Code
- $_SESSION['Reg_Id'] = $newId;
- $_SESSION['Reg_Name'] = $name;
- $_SESSION['Reg_Password'] = $password;
- $_SESSION['Reg_Location'] = "Home";
- $_SESSION['Reg_Type'] = "customer";
- // Always Echo your data at the end of your code.
- echo json_encode(['status' => 'success', 'message' => 'account registered']);
- }
- // Recommendation:
- //
- // It is best pratice to store the password as a hash such as a **sha1** with salt and paper,
- // such as:
- // <?php $password_hash = hash('sha1', 'S@lT' . $password . 'P3pp3r'); ?>
- //
- ?>
Advertisement
Add Comment
Please, Sign In to add comment