<?php
// Bağlantı bilgileri
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "memoryhackers";
try {
// Veritabanı bağlantısı
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Veritabanına başarıyla bağlandı!";
} catch(PDOException $e) {
echo "Veritabanı bağlantı hatası: " . $e->getMessage();
}
// Veri ekleme
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$ad = $_POST['ad'];
$soyad = $_POST['soyad'];
$email = $_POST['email'];
$stmt = $conn->prepare("INSERT INTO kullanici (ad, soyad, email) VALUES (:ad, :soyad, :email)");
$stmt->bindParam(':ad', $ad);
$stmt->bindParam(':soyad', $soyad);
$stmt->bindParam(':email', $email);
try {
$stmt->execute();
echo "Veri başarıyla eklendi!";
} catch(PDOException $e) {
echo "Veri ekleme hatası: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Veri Ekleme</title>
</head>
<body>
<form method="POST" action="index.php">
<label for="ad">Ad:</label>
<input type="text" name="ad" id="ad" required>
<br>
<label for="soyad">Soyad:</label>
<input type="text" name="soyad" id="soyad" required>
<br>
<label for="email">Email:</label>
<input type="email" name="email" id="email" required>
<br>
<input type="submit" value="Ekle">
</form>
</body>
</html>