49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Portal: Registrieren</title>
|
|
</head>
|
|
<body>
|
|
<h2>Registrieren</h2>
|
|
<form>
|
|
<label>E-Mail: <input name="email"></label><br>
|
|
<label>Passwort: <input type="password" name="pw" > </label>
|
|
<button type="submit">Registrieren</button>
|
|
</form>
|
|
</body>
|
|
</html>
|
|
<?php
|
|
require_once '../inc/db_connection_function.php';
|
|
$dbh = db_connect();
|
|
$errors = '';
|
|
|
|
if(!empty($_REQUEST)) { // Button wurde gedrückt?
|
|
if($_REQUEST['email'] != '' AND $_REQUEST['pw'] != ''){ // Alle Felder gedrückt?
|
|
$email = $_REQUEST['email'];
|
|
$pw = $_REQUEST['pw'];
|
|
|
|
$query = "INSERT INTO user VALUES (NULL, :email, :pw)";
|
|
$stmt = $dbh->prepare($query);
|
|
|
|
$stmt->bindParam(':email', $email);
|
|
$stmt->bindParam(':pw', $pw);
|
|
|
|
try {
|
|
$stmt->execute();
|
|
} catch(PDOException $e){
|
|
$errMsg = $e->getMessage();
|
|
$errCode = $e->getCode();
|
|
|
|
switch($errCode) {
|
|
case "23000": $custErrMsg = "<p>Email-Adress already exists!</p>"; break;
|
|
default: $custErrMsg = "<p>Oooops, something went wrong!</p>";
|
|
}
|
|
echo $custErrMsg;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if ($errors != "") echo $errors; |