PHP MYSQL

SIMPLE CONTENT MANAGEMENT SYSTEM WITH PHP MYSQL

`content_id` `content_title` `content_text`

CONTENTS TABLE

01

INT(11) PRIMARY KEY VARCHAR(255) TEXT

<form method="post">   CONTENT ID   <input type="hidden" name="id"/>   TITLE   <input type="text" name="title"/>   TEXT   <textarea name="txt"></textarea>   <input type="submit" value="Save"/> </form>

SAVE CONTENTS HTML FORM

02

CONNECT TO DATABASE $pdo = new PDO("mysql:host=HOST; dbname=NAME;charset=utf8", USER, PASSWORD);

PHP SAVE CONTENTS (A)

03

PHP SAVE CONTENTS (B)

04

REPLACE SQL $stmt = $pdo->prepare("REPLACE INTO `contents` (`content_id`, `content_title`, `content_text`) VALUES (?,?,?)");

EXECUTE SQL $stmt->execute([$_POST["id"], $_POST["title"], $_POST["txt"]);

PHP LOAD CONTENTS (A)

05

CONNECT TO DATABASE $pdo = new PDO("mysql:host=HOST; dbname=NAME;charset=utf8", USER, PASSWORD);

FETCH $id = 123; $stmt->execute([$id]); $content = $stmt->fetch();

PHP LOAD CONTENTS (B)

06

SELECT SQL $stmt = $pdo->prepare("SELECT * FROM `contents` WHERE `content_id`=?");

<h1>   <?=$content['content_title']?> </h1> <p>     <?=$content['content_text']?>  </p>

DISPLAY HTML CONTENTS

07