Files
marmeladenladen/db/datahandler.php
2022-05-02 10:04:02 +02:00

46 lines
1.7 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->email);
$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);
$postalcode = testinput($data->postalcode);
$role = "customer";
$password = password_hash($password, PASSWORD_DEFAULT);
require($_SERVER['DOCUMENT_ROOT'] . '/config/setupDBAccess.php');
$sql2 = "INSERT IGNORE INTO `cities` (`city_id`, `postalcode`, `name`) VALUES (?,?,?)";
$sql = "INSERT INTO `user` (`user_id`, `username`, `password`, `email`, `phone`, `salutation`, `firstname`, `lastname`, `address`, `plz`, `role`, `created_at`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
$stmtUser = $db->prepare($sql);
$stmtCities = $db->prepare($sql2);
$stmtUser->bind_param("ssssssssss", null, $username, $password, $email, $phone, $salutation, $firstname, $lastname, $street, $postalcode, $role, null);
$stmtCities->bind_param("sss", null, $postalcode, $coty);
if ($stmtUser->execute() && $stmtCities->execute() && $stmtAddress->execute()) {
return true;
} else {
return false;
}
$stmtUser->close();
$stmtCities->close();
$stmtAddress->close();
$db->close();
}
}
?>