커뮤니티

고용노동부, 산업인력공단과 함께하는 강원도 유일한 기업중심 IT전문교육기관 ICT융합캠퍼스만의 특별한교육입니다.
공인 IT숙련기술인의 다양한 접근방법으로 전문가다운 실무교육을 받을 수 있습니다.

Category

교육강좌

WEB WEB3 - PHP & MySQL - 활용 - 글생성

페이지 정보

작성자 관리자 댓글 0건 조회 3,247회 작성일 20-06-08 11:06

본문

활용 - 글생성

수업소개

mysqli API를 활용해서 MySQL에 글을 생성하는 방법을 알아봅니다.

 

 

강의

 

예제

변경사항

index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WEB</title>
</head>
<body>
<h1>WEB</h1>
<ol>
<li>HTML</li>
</ol>
<a href="create.php">create</a>
<h2>Welcome</h2>
Lorem ipsum dolor sit amet, consectetur adipisicing elit
</body>
</html>

create.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WEB</title>
</head>
<body>
<h1>WEB</h1>
<ol>
<li>HTML</li>
</ol>
<form action="process_create.php" method="POST">
<p><input type="text" name="title" placeholder="title"></p>
<p><textarea name="description" placeholder="description"></textarea></p>
<p><input type="submit"></p>
</form>
</body>
</html>

process_create.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$conn = mysqli_connect(
'localhost',
'root',
'111111',
'opentutorials');
$sql = "
INSERT INTO topic
(title, description, created)
VALUES(
'{$_POST['title']}',
'{$_POST['description']}',
NOW()
)
";
$result = mysqli_query($conn, $sql);
if($result === false){
echo '저장하는 과정에서 문제가 생겼습니다. 관리자에게 문의해주세요';
error_log(mysqli_error($conn));
} else {
echo '성공했습니다. <a href="index.php">돌아가기</a>';
}
?>

 

  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기

답변목록

등록된 답변이 없습니다.