47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
// register.php
|
|
require 'config.php';
|
|
|
|
|
|
// Verbindung herstellen
|
|
$conn = new mysqli($host, $user, $pass, $db);
|
|
|
|
// Verbindung prüfen
|
|
if ($conn->connect_error) {
|
|
die("Verbindung fehlgeschlagen: " . $conn->connect_error);
|
|
}
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$input_username = $_POST['username'];
|
|
$input_password = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
|
|
|
$sql = "INSERT INTO users (username, password) VALUES (?, ?)";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->bind_param("ss", $input_username, $input_password);
|
|
|
|
if ($stmt->execute()) {
|
|
echo "Registrierung erfolgreich!";
|
|
} else {
|
|
echo "Fehler: " . $sql . "<br>" . $conn->error;
|
|
}
|
|
|
|
$stmt->close();
|
|
}
|
|
|
|
$conn->close();
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Registrierung</title>
|
|
</head>
|
|
<body>
|
|
<h2>Registrierung</h2>
|
|
<form method="post" action="register.php">
|
|
Username: <input type="text" name="username" required><br>
|
|
Passwort: <input type="password" name="password" required><br>
|
|
<input type="submit" value="Registrieren">
|
|
</form>
|
|
</body>
|
|
</html>
|