
개발 대상은 [회원정보 수정] 페이지이다.
구성은 다음과 같다.
mypage_edit.php : 회원정보 수정 양식 페이지
mypageedit_proc.php : 회원정보 수정 처리 페이지
mypage_edit.css : 회원정보 수정 CSS
<mypage_edit.php>
<?php
session_start();
if (!isset($_SESSION["user_id"])) {
echo "<script>
alert('권한이 없습니다.');
history.go(-1);
</script>";
exit;
}
include "../db/db_con.php";
$sql = "select * from user where user_id = '{$_SESSION['user_id']}'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_assoc($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원정보 수정</title>
<link rel="stylesheet" href="../css/mypage_edit.css">
<script src="./sign_up.js"></script>
</head>
<body>
<?php include "../include/header.php" ?>
<div class="mypage-edit-container">
<h2>회원정보 수정</h2>
<form class="mypage-edit-form" method="post" action="mypageedit_proc.php">
<div class="mypage-edit-row">
<label>아이디</label>
<input value="<?php echo $row["user_id"]?>" disabled>
</div>
<div class="mypage-edit-row">
<label for="input_pw">비밀번호</label>
<input type="password" id="input_pw" name="input_pw" placeholder="새 비밀번호 입력">
</div>
<div class="mypage-edit-row">
<label for="input_pw2">비밀번호 확인</label>
<input type="password" id="input_pw2" name="input_pw2" placeholder="비밀번호 확인">
</div>
<div class="mypage-edit-row">
<label for="input_name">사용자명</label>
<input id="input_name" name="input_name" value="<?php echo $row["user_name"]?>">
</div>
<div class="mypage-edit-row">
<label for="input_mail">이메일(선택)</label>
<input id="input_mail" name="input_mail" value="<?php echo $row["user_mail"]?>">
</div>
<div class="mypage-edit-actions">
<input type="submit" value="수정완료">
<button type="button" onclick="history.back()">이전</button>
</div>
</form>
</div>
</body>
</html>
| mypage_edit.php |
|---|
![]() |
<mypageedit_proc.php>
<?php
if ($_POST["input_pw"] != $_POST["input_pw2"]) {
echo "<script>
alert('입력된 비밀번호가 일치하지 않습니다');
history.go(-1);
</script>";
exit;
}
include "../db/db_con.php";
$input_pw = hash('sha256', $_POST["input_pw"]);
$input_name = $_POST["input_name"];
$input_mail = $_POST["input_mail"];
$res = "";
session_start();
$user_id = $_SESSION["user_id"];
if (empty($_POST["input_pw"]) and empty($input_name) and empty($input_mail)) {
echo "<script>
alert('변경 사항이 없습니다.');
location.href='./mypage_edit.php'
</script>";
}
if(!empty($_POST["input_pw"])) {
$sql = "update user set user_pw = '$input_pw' where user_id = '$user_id'";
mysqli_query($con, $sql);
$res .= "[비밀번호] ";
}
if(!empty($input_name)) {
$sql = "update user set user_name = '$input_name' where user_id = '$user_id'";
mysqli_query($con, $sql);
$res.= "[사용자명] ";
}
if(!empty($input_mail)) {
$sql = "update user set user_mail = '$input_mail' where user_id = '$user_id'";
mysqli_query($con, $sql);
$res .= "[이메일] ";
}
mysqli_close($con);
echo "<script>
alert('{$res}이(가) 수정되었습니다.');
location.href='./mypage.php'
</script>";
?>
| 1. 마이페이지 → 회원정보 수정 (영상) |
|---|
![]() |
| 2. 비밀번호 불일치시 |
|---|
![]() |
| 3. 회원정보 수정시 |
|---|
![]() |
| ↑ 회원정보 1개 수정 |
![]() |
| ↑ 회원정보 2개 수정 |
![]() |
| ↑ 회원정보 3개 수정 |