我创建了一个登录页面和一个管理页面。管理员页面创建新帖子
在管理页面上,我创建了两个文本字段,第一个是标题,第二个是内容。我也创建了一个提交按钮。
我有一个名为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