<?php include_once 'articleData.php'; $dataModel = new ArticlesData(); $list = $dataModel->all(); ?> <html> <head> </head> <body> <h3>Articles</h3> <?php foreach ($list as $article) { ?> <div class="article"> <div class="title"><?php echo $article->title; ?> </div> <div class="content"><?php echo $article->content; ?> </div> </div> <?php } ?> </body> </html>
<?php function redir($url = 'http://test4.com:81/blog/form.php') { header('location:' . $url); } if (empty($_POST) || !isset($_POST['title']) || !isset($_POST['content'])) { redir(); } $userId = 2; $insertData = ['title' => '', 'content' => $_POST['content'], 'user_id' => $userId]; $artData = new ArticlesData(); $artId = $artData->add($insertData);