34702-vm/register.php
2025-10-05 21:53:53 +00:00

87 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once 'header.php';
require_once 'db/config.php';
$errors = [];
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$password_confirm = $_POST['password_confirm'] ?? '';
if (empty($name)) {
$errors[] = 'Ad Soyad zorunludur.';
}
if (empty($email)) {
$errors[] = 'E-posta zorunludur.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Geçersiz e-posta formatı.';
}
if (empty($password)) {
$errors[] = 'Şifre zorunludur.';
}
if ($password !== $password_confirm) {
$errors[] = 'Şifreler eşleşmiyor.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$errors[] = 'Bu e-posta adresi zaten kayıtlı.';
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)");
$stmt->execute([$name, $email, $hashed_password]);
$success = 'Başarıyla kayıt oldunuz! Giriş yapabilirsiniz.';
}
} catch (PDOException $e) {
$errors[] = "Veritabanı hatası: " . $e->getMessage();
}
}
}
?>
<div class="container">
<h1>Kayıt Ol</h1>
<?php if (!empty($errors)): ?>
<div class="errors">
<?php foreach ($errors as $error): ?>
<p><?php echo htmlspecialchars($error); ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="success">
<p><?php echo htmlspecialchars($success); ?></p>
</div>
<?php else: ?>
<form action="/register.php" method="post">
<div class="form-group">
<label for="name">Ad Soyad</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="email">E-posta</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Şifre</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="password_confirm">Şifre Tekrar</label>
<input type="password" id="password_confirm" name="password_confirm" required>
</div>
<button type="submit" class="btn">Kayıt Ol</button>
</form>
<?php endif; ?>
</div>
<?php require_once 'footer.php'; ?>