Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
관계형 데이터베이스 도입 - 글쓰기 구현
  • Loading branch information
egoing committed Feb 22, 2018
1 parent 51c719a commit 31a0414
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 8 additions & 4 deletions create.php
Expand Up @@ -13,10 +13,13 @@
$list = $list."<li><a href=\"index.php?id={$row['id']}\">{$escaped_title}</a></li>";
}

$article = array(
'title'=>'Welcome',
'description'=>'Hello, web'
);
$sql = "SELECT * FROM author";
$result = mysqli_query($conn, $sql);
$select_form = '<select name="author_id">';
while($row = mysqli_fetch_array($result)){
$select_form .= '<option value="'.$row['id'].'">'.$row['name'].'</option>';
}
$select_form .= '</select>';
?>
<!doctype html>
<html>
Expand All @@ -32,6 +35,7 @@
<form action="process_create.php" method="POST">
<p><input type="text" name="title" placeholder="title"></p>
<p><textarea name="description" placeholder="description"></textarea></p>
<?=$select_form?>
<p><input type="submit"></p>
</form>
</body>
Expand Down
9 changes: 5 additions & 4 deletions process_create.php
Expand Up @@ -4,19 +4,20 @@
'root',
'111111',
'opentutorials');

$filtered = array(
'title'=>mysqli_real_escape_string($conn, $_POST['title']),
'description'=>mysqli_real_escape_string($conn, $_POST['description'])
'description'=>mysqli_real_escape_string($conn, $_POST['description']),
'author_id'=>mysqli_real_escape_string($conn, $_POST['author_id'])
);

$sql = "
INSERT INTO topic
(title, description, created)
(title, description, created, author_id)
VALUES(
'{$filtered['title']}',
'{$filtered['description']}',
NOW()
NOW(),
{$filtered['author_id']}
)
";
$result = mysqli_query($conn, $sql);
Expand Down

0 comments on commit 31a0414

Please sign in to comment.