<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
</head>
<body>
<!--POSTMAN 앱: HTTP GET/POST 테스트 앱 -->
<!-- GET/POST(파라미터, 파일전송 기능 ) -->
<!-- 테스트 방법 : localhost/ex31.php -->
<form method="post" action="ex37.php">
키값 : <input type="text" name="user_index"> <br />
찾는 아이디 : <input type="text" name="user_id"> <br />
비밀번호 : <input type="password" name="user_pw"> <br />
핸드폰 : <input type="text" name="phone"> <br />
<input type="submit">
</form>
</body>
</html>
<?php
//데이터 수정 UPDATE
//PHP Obejct 방식, MySQLI
//POST 방식으로 user_id, user_pw를 넘겨서 회원이 있는지 로그인 처리한다
header('Content-Type: text/html; charset=utf8');
$connect=mysqli_connect("localhost","root","111111","mydb");
// 서버 url 주소, 아이디, 암호 , db이름
if($connect->connect_errno){ // db 연결 실패시
echo"Failed to connect to MySQL: " .$connect->connect_errno;
exit;
}
//mySQL의 한글 데이타 깨지지 않도록 문자 인코딩 지정
mysqli_set_charset($connect,"utf8");
$user_index=$_POST["user_index"];
$user_id=$_POST["user_id"];
$user_pw=$_POST["user_pw"];
$phone=$_POST["phone"];
if(!isset($user_id)){
exit;
}
//SQL 문 작성
$sql ="UPDATE users SET user_id='$user_id',
user_pw='$user_pw' ,phone ='$phone' WHERE user_index=$user_index";
//SQL 쿼리 전송 (실행)
$result=$connect->query($sql);
//성공했는지 확인
if($result===TRUE){
echo "데이타가 성공적으로 업데이트되었습니다.";
}else{
echo "데이타 업데이트가 실패했습니다. ";
//에러가 발생하면 자동적으로 $connect에 에러 내용이 담김
echo "SQL문 : " . $sql ."<br>" . $connect->error;
}
//결과 값 메모리 해제
$result->free();
//db 연결 닫기
mysqli_close();
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
</head>
<body>
<!--POSTMAN 앱: HTTP GET/POST 테스트 앱 -->
<!-- GET/POST(파라미터, 파일전송 기능 ) -->
<!-- 테스트 방법 : localhost/ex31.php -->
<form method="post" action="ex36.php">
아이디 : <input type="text" name="user_id"> <br />
<input type="submit">
</form>
</body>
</html>
<?php
//데이터 삭제 DELETE
//PHP Obejct 방식, MySQLI
//POST 방식으로 user_id, user_pw를 넘겨서 회원이 있는지 로그인 처리한다
header('Content-Type: text/html; charset=utf8');
$connect=mysqli_connect("localhost","root","111111","mydb");
// 서버 url 주소, 아이디, 암호 , db이름
if($connect->connect_errno){ // db 연결 실패시
echo"Failed to connect to MySQL: " .$connect->connect_errno;
exit;
}
//mySQL의 한글 데이타 깨지지 않도록 문자 인코딩 지정
mysqli_set_charset($connect,"utf8");
$user_id=$_POST["user_id"];
if(!isset($user_id)){
exit;
}
//SQL 문 작성
$sql ="DELETE FROM users WHERE user_id='$user_id'" ;
//SQL 쿼리 전송 (실행)
$result=$connect->query($sql);
//성공했는지 확인
if($result===TRUE){
echo "데이타가 성공적으로 삭제되었습니다.";
}else{
echo "데이타 삭제가 실패했습니다. ";
//에러가 발생하면 자동적으로 $connect에 에러 내용이 담김
echo "SQL문 : " . $sql ."<br>" . $connect->error;
}
//결과 값 메모리 해제
$result->free();
//db 연결 닫기
mysqli_close();
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
</head>
<body>
<!--POSTMAN 앱: HTTP GET/POST 테스트 앱 -->
<!-- GET/POST(파라미터, 파일전송 기능 ) -->
<!-- 테스트 방법 : localhost/ex31.php -->
<form method="post" action="ex35.php">
아이디 : <input type="text" name="user_id"> <br />
비밀번호 : <input type="password" name="user_pw"> <br />
핸드폰 : <input type="text" name="phone"> <br />
<input type="submit">
</form>
</body>
</html>
<?php
//데이터 추가 insert
//PHP Obejct 방식, MySQLI
//POST 방식으로 user_id, user_pw를 넘겨서 회원이 있는지 로그인 처리한다
header('Content-Type: text/html; charset=utf8');
$connect=mysqli_connect("localhost","root","111111","mydb");
// 서버 url 주소, 아이디, 암호 , db이름
if($connect->connect_errno){ // db 연결 실패시
echo"Failed to connect to MySQL: " .$connect->connect_errno;
exit;
}
//mySQL의 한글 데이타 깨지지 않도록 문자 인코딩 지정
mysqli_set_charset($connect,"utf8");
$user_id=$_POST["user_id"];
$user_pw=$_POST["user_pw"];
$phone=$_POST["phone"];
if(!isset($user_id)){
exit;
}
//SQL 문 작성
$sql ="INSERT INTO users VALUES (0,'$user_id','$user_pw',' $phone')";
//SQL 쿼리 전송 (실행)
$result=$connect->query($sql);
//성공했는지 확인
if($result===TRUE){
echo "데이타가 성공적으로 추가되었습니다.";
}else{
echo "데이타 추가가 실패했습니다. ";
//에러가 발생하면 자동적으로 $connect에 에러 내용이 담김
echo "SQL문 : " . $sql ."<br>" . $connect->error;
}
//결과 값 메모리 해제
mysqli_free();
//db 연결 닫기
mysqli_close();
?>