-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
53 lines (41 loc) · 1.33 KB
/
signup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require("dbconfig.php");
// 연결
$conn = new mysqli($server_name, $db_username, $db_password, $db_name);
// 연결 확인
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 사용자 입력값 받아오기
$email = $_POST["email"];
$password = $_POST["password"];
$username = $_POST["username"];
$age = $_POST["age"];
$sex = $_POST["sex"];
// 이메일 중복 확인
$check_email_sql = "SELECT * FROM user WHERE email = ?";
$stmt = $conn->prepare($check_email_sql);
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// 중복된 이메일 존재
$error = "중복된 이메일입니다.";
if (!empty($error)):
echo "<div class='alert alert-danger'>$error</div>";
endif;
} else {
// 새로운 사용자 정보 삽입
$stmt = $conn->prepare("INSERT INTO user (email, pw, name, age, sex) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssis", $email, $password, $username, $age, $sex);
if ($stmt->execute()) {
header("location: login.html");
} else {
echo "Error: " . $stmt->error;
}
}
$stmt->close();
}
$conn->close();
?>