Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once __DIR__ . "/../config/conn.php";
- if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
- print_r($_POST);
- //backend_validation_file
- require __DIR__."/../backend_validation/code.php";
- $username = $_POST['user_name'];
- $firstname = validate_firstName($_POST['first_name']) ;
- $lastname = validate_lastName($_POST['last_name']);
- $email = validate_email($_POST['email']);
- $phone = validate_phone($_POST['phone']);
- $age = validate_Age($_POST['age']);
- $password = compare_passwords($_POST['password'],$_POST['no-password']);
- $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
- $target_file = file_validation($_FILES["fileToUpload"]);
- $checkQuery = "SELECT * FROM `user` WHERE username = ?";
- $checkStmt = mysqli_prepare($conn, $checkQuery);
- mysqli_stmt_bind_param($checkStmt, 's', $username);
- mysqli_stmt_execute($checkStmt);
- $result = mysqli_stmt_get_result($checkStmt);
- if (mysqli_num_rows($result) > 0) {
- // In the script on the initial page:
- echo '<script>';
- echo ' window.location.href = "/../ajax_insert/index.php?alert=Username exists";';
- echo '</script>';
- } else {
- if(($firstname!="false")&&($lastname!="false")&&($email!="false")&&($phone!="false")&&($age!="false")&&($password!="false")){
- // "<-------Preparing data insertion--------->"
- $query = 'INSERT INTO user(username,first_name,last_name,email,phone,age,password,fileLocation) VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
- $stmt = mysqli_prepare($conn, $query);
- mysqli_stmt_bind_param($stmt, 'ssssiiss', $username, $firstname, $lastname, $email, $phone, $age, $hashedPassword, $target_file);
- if (mysqli_stmt_execute($stmt)){
- // echo "Sent!";
- echo '<script>';
- echo ' window.location.href = "/../ajax_insert/index.php?alert=Data Sent!;';
- echo '</script>';
- // // No output before header!
- // mysqli_stmt_close($stmt);
- // header("Location: login.php");
- // exit;
- } else {
- echo "Error: " . mysqli_connect_error($conn);
- }
- mysqli_stmt_close($stmt);
- }else{
- echo "Fix all of the inputs";
- }
- }
- mysqli_stmt_close($checkStmt);
- }
- mysqli_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement