-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
43 lines (33 loc) · 1.47 KB
/
process.php
File metadata and controls
43 lines (33 loc) · 1.47 KB
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
<?php
//데이터베이스 접속
require_once('conn.php');
//저자가 user 테이블에 존재하는지 여부를 체크
$author = mysqli_real_escape_string($conn,$_POST['author']);
$sql = "SELECT * FROM `user` WHERE `name` = '".$author."'";
//$sql = "SELECT * FROM `user` WHERE `name` = '{$author}'";
//user_id 알아내기!!!!!!
$result = mysqli_query($conn, $sql);
if($result->num_rows > 0){
//존재한다면 user.id을 알아낸다
$row = mysqli_fetch_assoc($result);
$user_id = $row['id'];
}else{
//존재하지 않는다면 저자를 user 테이블에 추가 후 id를 알아낸다
$sql = "INSERT INTO user (id, name, password) VALUES(NULL, '{$author}', '');";
mysqli_query($conn, $sql);
//방금 인서트한 테이블에 추가된 행의 아이디를 알아내기
$user_id = mysqli_insert_id($conn);
}
$title = mysqli_real_escape_string($conn, $_POST['title']);
$description = mysqli_real_escape_string($conn, $_POST['description']);
$sql = "INSERT INTO
`topic`
(`id`, `title`, `description`, `author`, `created`)
VALUES (NULL, '{$title}', '{$description}', '{$user_id}', now());";
/////////$sql = "INSERT INTO" `user` (`id`, `name`) VALUES (NULL, '{$user_id}')
mysqli_query($conn, $sql);
//사용자를 index.php로 이동(리다이렉션)
header('location: index.php');
//제목,저자,본문 등을 topic 테이블에 추가
//print_r($_POST);//배열에 접근하는 print_r이거 정리7의 19분에 설명 잘 되어있음
?>