<?php
class User
{
private $values = [];
public function __construct(string ...$keys)
{
foreach ($keys as $key) {
if (isset($_POST[$key])) {
$values[$key] = $_POST[$key];
} else {
$values['errors'] = array(
"error_$key" => true
);
}
}
}
public function __get($name)
{
return $values[$name] ? : null;
}
}
$user = new User(['email', 'first', 'last', 'uid', 'pwd1', 'pwd2']);
if (!isset($user->pwd1, $user->pwd2) || $user->pwd1 !== $user->pwd2) {
$user->errors = array(
"error_pwds" => true
);
}
if ($user->errors !== []) {
header('Location: https://drohneglobal.de/login/registrierung.php?' . http_build_query($user->errors));
exit();
}
try {
$passwort = password_hash($_POST['pwd1'], PASSWORD_DEFAULT);
$db = new PDO('mysql:host=.....;dbname=....', '....', '.....');
$sql = 'INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES (?, ?, ?, ?, ?)';
$werte = [$user->first, $user->last, $user->email, $user->uid, $passwort];
$kommando = $db->prepare($sql);
$kommando->execute($werte);
header('Location: https://drohneglobal.de/login/registrierung.php');
} catch (PDOException $e) {
echo 'Fehler: ' . htmlspecialchars($e->getMessage());
}
Comments