Files
marmeladenladen/db/datahandler.php
2022-05-02 09:21:19 +02:00

49 lines
1.8 KiB
PHP

<?php
include($_SERVER['DOCUMENT_ROOT'] . '/models/user.class.php');
include($_SERVER['DOCUMENT_ROOT'] . '/logic/testinput.php');
class DataHandler
{
public function registerUser($data)
{
$username = testinput($data->username);
$password = testinput($data->password);
$email = testinput($data->email);
$phone = testinput($data->phone);
$salutation = testinput($data->salutation);
$firstname = testinput($data->firstname);
$lastname = testinput($data->lastname);
$street = testinput($data->street);
$streetnumber = testinput($data->streetnumber);
$postalcode = testinput($data->postalcode);
$country = testinput($data->country);
$password = password_hash($password, PASSWORD_DEFAULT);
require($_SERVER['DOCUMENT_ROOT'] . '/config/setupDBAccess.php');
$sql = "INSERT INTO user (username, password, email, phone, salutation, firstname, lastname) VALUES (?,?,?,?,?,?,?)";
$sql2 = "INSERT IGNORE INTO cities (postalcode, name) VALUES (?,?)";
$sql3 = "INSERT INTO address (street, streetnumber, postalcode, country) VALUES (?,?,?,?)";
$stmtUser = $db->prepare($sql);
$stmtCities = $db->prepare($sql2);
$stmtAddress = $db->prepare($sql3);
$stmtUser->bind_param("sssssss", $username, $password, $email, $phone, $salutation, $firstname, $lastname);
$stmtCities->bind_param("ss", $postalcode, $country);
$stmtAddress->bind_param("ssss", $street, $streetnumber, $postalcode, $country);
if ($stmtUser->execute() && $stmtCities->execute() && $stmtAddress->execute()) {
return true;
} else {
return false;
}
$stmtUser->close();
$stmtCities->close();
$stmtAddress->close();
$db->close();
}
}
?>