我創建了一個登錄頁面和一個管理頁面。管理員頁面創建新帖子
在管理頁面上,我創建了兩個文本字段,第一個是標題,第二個是內容。我也創建了一個提交按鈕。
我有一個名爲node的表的數據庫。
在該表中我創建了:id(1,2,3 ...),author_id(1 = me),標題(它是標題),文本(它是內容)和日期(發佈時)。
現在我想要的是當我按提交按鈕時,作者,標題,文本和日期作爲新帖子出現在頁面上。當我按下「發佈您的問題」按鈕時,這幾乎是一回事。
我創建從SQL 3點測試新聞發佈,它的工作,但它要好得多,如果我可以從管理頁面做到這一點。 :)
我非常感謝,如果你能寫得很好,我從來沒有這樣做,我真的不知道如何做到這一點。
之前有人提供:我不想創建joomla或drupal網站。
最終工作的版本:(感謝半絲)
<?php
ob_start();
session_start();
?>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css" type="text/css" media="screen"/>
<?php
if (isset($_COOKIE["user"]))
{
include('sql.php');
$username =$_COOKIE["user"];
$user = mysql_fetch_row(mysql_query("select * from user where
name='$username'"));
if (empty($_GET['action']))
{
//This is where you add to database
if (!empty($_POST['submit']) && $_POST['submit']=='submit'){
//do any validation if required, like not empty header and not empty body etc here
$title = mysql_real_escape_string($_POST['title']);
$text = mysql_real_escape_string($_POST['text']);
}
//insert to the database
mysql_query("INSERT INTO hearthstone.node
(author_id , title , text , date)
VALUES ('1', '$title', '$text', NOW());");
}
?>
<div id="adminmenu">Logged in as <b>
<?php print $user[1];?></b>
<span style="margin: 15px;"><br></span>
<?php include('logout.php'); ?>
<span style="margin: 15px;"></span>
<form method="post" action="">
<p>Title:</p>
<p><input type="text" maxlength="255" name="title" id="title" size="60"></p>
<p>Body content:</p>
<p><textarea cols="60" rows="20" name="text" id="text"></textarea></p>
<p><input type="submit" name="submit" id="submit" value="submit"></p>
</form>
</div>
<?php
}
else
{
include('login.php');
}
?>
您可以將代碼發佈到您的管理頁面嗎? – bansi
我現在加入.... – Phoenixy