Advertisement
Daniel3996

action/action.php

Mar 26th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. <?php
  2.  
  3. require_once __DIR__ . "/../config/conn.php";
  4. if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
  5. print_r($_POST);
  6. //backend_validation_file
  7. require __DIR__."/../backend_validation/code.php";
  8.  
  9.  
  10. $username = $_POST['user_name'];
  11. $firstname = validate_firstName($_POST['first_name']) ;
  12. $lastname = validate_lastName($_POST['last_name']);
  13. $email = validate_email($_POST['email']);
  14. $phone = validate_phone($_POST['phone']);
  15. $age = validate_Age($_POST['age']);
  16. $password = compare_passwords($_POST['password'],$_POST['no-password']);
  17. $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
  18. $target_file = file_validation($_FILES["fileToUpload"]);
  19.  
  20.  
  21. $checkQuery = "SELECT * FROM `user` WHERE username = ?";
  22. $checkStmt = mysqli_prepare($conn, $checkQuery);
  23. mysqli_stmt_bind_param($checkStmt, 's', $username);
  24. mysqli_stmt_execute($checkStmt);
  25. $result = mysqli_stmt_get_result($checkStmt);
  26.  
  27. if (mysqli_num_rows($result) > 0) {
  28.  
  29. // In the script on the initial page:
  30. echo '<script>';
  31. echo ' window.location.href = "/../ajax_insert/index.php?alert=Username exists";';
  32. echo '</script>';
  33. } else {
  34. if(($firstname!="false")&&($lastname!="false")&&($email!="false")&&($phone!="false")&&($age!="false")&&($password!="false")){
  35.  
  36.  
  37. // "<-------Preparing data insertion--------->"
  38.  
  39. $query = 'INSERT INTO user(username,first_name,last_name,email,phone,age,password,fileLocation) VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
  40.  
  41. $stmt = mysqli_prepare($conn, $query);
  42. mysqli_stmt_bind_param($stmt, 'ssssiiss', $username, $firstname, $lastname, $email, $phone, $age, $hashedPassword, $target_file);
  43.  
  44. if (mysqli_stmt_execute($stmt)){
  45. // echo "Sent!";
  46. echo '<script>';
  47. echo ' window.location.href = "/../ajax_insert/index.php?alert=Data Sent!;';
  48. echo '</script>';
  49.  
  50. // // No output before header!
  51. // mysqli_stmt_close($stmt);
  52. // header("Location: login.php");
  53. // exit;
  54.  
  55. } else {
  56.  
  57. echo "Error: " . mysqli_connect_error($conn);
  58. }
  59.  
  60. mysqli_stmt_close($stmt);
  61. }else{
  62. echo "Fix all of the inputs";
  63. }
  64. }
  65. mysqli_stmt_close($checkStmt);
  66. }
  67.  
  68. mysqli_close($conn);
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement