changed a lot

This commit is contained in:
StockiP
2022-05-02 12:24:22 +02:00
parent 9e28e83146
commit 8e91e4a8f6
4 changed files with 60 additions and 12 deletions

View File

@@ -3,10 +3,9 @@
<div class="row">
<div class="col-3">
<select name="salutation" id="salutation">
<option disabled selected value="0" style="display:none">Anrede</option>
<option value="Frau">Frau</option>
<option value="Herr">Herr</option>
<option value="Person">Person</option>
<option selected value="Person">Person</option>
</select>
</div>
<div class="col-4">

View File

@@ -32,7 +32,7 @@ class DataHandler
$stmtCities->bind_param("sss", null, $postalcode, $coty);
if ($stmtUser->execute() && $stmtCities->execute() && $stmtAddress->execute()) {
return true;
return $data;
} else {
return false;
}

View File

@@ -1,7 +1,7 @@
const password = document.getElementById('password');
const password2 = document.getElementById('password2');
password2.addEventListener('change', checkPassword);
const form = document.getElementById('marmeladenLadenRegisterForm');
form.addEventListener('submit', register);
@@ -15,16 +15,21 @@ async function register(event) {
//create object with form data
const data = {};
formData.forEach((value, key) => data[key] = value);
//log data on console
datastring = JSON.stringify(data);
console.log(data);
console.log(datastring);
//send data to php with Ajax
$.ajax({
url: '../logic/serviceLogic.php',
url: '../logic/registerLogic.php',
type: 'POST',
data: {method: 'register', data: data},
datatype: 'json',
data: datastring,
cache: false,
datatype: 'text',
success: function (response) {
if (response === 'success') {
window.location.replace('index.html');
console.log(response);
if (response == 'success') {
window.location.href = '../index.html';
} else {
alert(response);
}
@@ -33,8 +38,6 @@ async function register(event) {
}
}
async function checkPassword() {
if (password.value != password2.value) {
password2.setCustomValidity('Passwords do not match');

46
logic/registerLogic.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/logic/testinput.php');
$data = json_decode(file_get_contents('php://input'));
$username = testinput($data->email);
$password = password_hash(testinput($data->password), PASSWORD_DEFAULT);
$email = testinput($data->email);
$phone = testinput($data->phone);
$salutation = testinput($data->salutation);
$firstname = testinput($data->firstname);
$lastname = testinput($data->lastname);
$street = testinput($data->street);
$postalcode = testinput($data->postalcode);
$city = testinput($data->city);
$role = "customer";
registerUser($username, $password, $email, $phone, $salutation, $firstname, $lastname, $street, $postalcode, $city, $role);
function registerUser($username, $password, $email, $phone, $salutation, $firstname, $lastname, $street, $postalcode, $city, $role)
{
require($_SERVER['DOCUMENT_ROOT'] . '/config/setupDBAccess.php');
$sql2 = "INSERT IGNORE INTO `cities` (`postalcode`, `name`) VALUES (?,?)";
$sql = "INSERT INTO `user` (`username`, `password`, `email`, `phone`, `salutation`, `firstname`, `lastname`, `address`, `plz`, `role`) VALUES (?,?,?,?,?,?,?,?,?,?)";
$stmtUser = $db->prepare($sql);
$stmtCities = $db->prepare($sql2);
$stmtUser->bind_param("ssssssssss", $username, $password, $email, $phone, $salutation, $firstname, $lastname, $street, $postalcode, $role);
$stmtCities->bind_param("is", $postalcode, $city);
if ($stmtCities->execute() && $stmtUser->execute()) {
$response = "success";
} else {
$response = "failure";
}
$stmtUser->close();
$stmtCities->close();
$db->close();
echo $response;
}