0

CMS を作成しており、それに追加ページを追加しています。

add.php として次のコードを使用しました。

<?php

session_start();

include_once('../include/connection.php');

if (isset($_SESSION['logged_in'])){
      if (isset($_POST['title'], $_POST['content'])) {
             $title = $_POST['title'];
             $content = $_POST['content'];

if (empty($title) or empty($content)) {
             $error = 'All Fields Are Required!';
}else{
     $query = $pdo->prepare('INSERT INTO articles (article_title, article_content, article_timestamp) VALUES(?, ?, ?)');
     $query->bindValue(1, $title);
     $query->bindValue(2, $content);
     $query->bindValue(3, $time());

     $query->execute();
    header('location: index.php');
}

}
          ?>

<html>
<head>
<title>testing</title>
<link rel="stylesheet" href="../style.css" />
</head>

<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>

<br />


<h4>Add Article</h4>

<?php if (isset($error)) { ?>
     <small style="color:#aa0000;"><?php echo $error; ?></small><br /><br />
<?php } ?>

<form action="add.php" method="post" autocomplete="off">

<input type="text" name="title" placeholder="Title" /><br /><br />
<textarea rows="15" cols="50" placeholder="content" name="Content"></textarea><br /><br />
<input type="submit" value="Add Article" />

</form>

</div>
</body>
</html>


<?php
}else{
       header('location: index.php');
}

?>

私の問題です。

私の ADD ARTICLE ボタンはページを更新するだけです

すべてのフィールドが必要であるという警告は表示されず要求したようにデータベースに何も追加されません。しかし、ページを更新します。

誰かが私が間違っている場所を教えてもらえますか?

ありがとうございました。

4

1 に答える 1