<?php
// 게시판 클래스
class Board
{
private $conn;
public function __construct($db)
{
$this->conn = $db;
}
// 글 등록
// bcode, id, name, subject, content, hit, ip, create_at
// NOW() -> 현재 시간 / 년-월-일 시:분:초
public function input($arr)
{
$sql = "INSERT INTO board(
bcode, id, name, subject, content, ip, create_at) VALUES(
:bcode, :id, :name, :subject, :content, :ip, NOW())";
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(":bcode", $arr["bcode"]);
$stmt->bindParam(":id", $arr["id"]);
$stmt->bindParam(":name", $arr["name"]);
$stmt->bindParam(":subject", $arr["subject"]);
$stmt->bindParam(":content", $arr["content"]);
$stmt->bindParam(":ip", $arr["ip"]);
$stmt->execute();
}
}




<?php
include "../inc/common.php"; // 세션
include "../inc/dbconfig.php"; // DB
include "../inc/board.php"; // 게시판 Class
include "../inc/member.php"; // 멤버 Class
$subject = (isset($_POST["subject"]) && $_POST["subject"] != "") ? $_POST["subject"] : "";
$content = (isset($_POST["content"]) && $_POST["content"] != "") ? $_POST["content"] : "";
$bcode = (isset($_POST["bcode"]) && $_POST["bcode"] != "") ? $_POST["bcode"] : "";
$mode = (isset($_POST["mode"]) && $_POST["mode"] != "") ? $_POST["mode"] : "";
if ($mode == "") {
$arr = ["result" => "empty_mode"];
die(json_encode($arr));
}
if ($bcode == "") {
$arr = ["result" => "empty_bcode"];
die(json_encode($arr));
}
$board = new Board($db);
$member = new Member($db);
if ($mode == "input") {
// bcode, id, name, subject, content, ip
if ($subject == "") {
$arr = ["result" => "empty_subject"];
die(json_encode($arr));
}
if ($content == "" || $content == "<p><br></p>") {
$arr = ["result" => "empty_content"];
die(json_encode($arr));
}
$memberArr = $member->getInfo($ss_id);
$name = $memberArr["name"];
$arr = [
"bcode" => $bcode,
"id" => $ss_id,
"name" => $name,
"subject" => $subject,
"content" => $content,
"ip" => $_SERVER["REMOTE_ADDR"]
];
$board->input($arr);
die(json_encode(["result" => "success"]));
}
Member Class - 회원정보 관리
// 아이디 가져오기 public function getInfo($id) { $sql = "SELECT * FROM member WHERE id=:id"; $stmt = $this->conn->prepare($sql); $stmt->bindParam(":id", $id); $stmt->setFetchMode(PDO::FETCH_ASSOC); $stmt->execute(); return $stmt->fetch(); }board_process.php
$member = new Member($db); $name = $memberArr["name"];
다음 시간에는 썸머노트 웹에디터에서 넘어온 이미지를 저장을 해보겠습니다.
감사합니다.