项目结构:
添加页面: 说明:这里只注重操作,对界面的美工没有下工夫,希望大家理解……
列表页面:
修改页面:
项目中所需的sql:
复制代码 代码如下:
create database form;
use form;
CREATE TABLE `message` (
`id` tinyint(1) NOT NULL auto_increment,
`user` varchar(25) NOT NULL,
`title` varchar(50) NOT NULL,
`content` tinytext NOT NULL,
`lastdate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;
conn.php
复制代码 代码如下:
$conn = @ mysql_connect(“localhost”, “root”, “”) or die(“数据库链接错误”);
mysql_select_db(“form”, $conn);
mysql_query(“set names ‘gbk'”);
?>
add.php
复制代码 代码如下:
include ‘conn.php’;
if($_POST[‘submit’]){
$sql=”INSERT INTO message(id,user,title,content,lastdate) VALUES (NULL, ‘$_POST[user]’, ‘$_POST[title]’, ‘$_POST[content]’, now())”;
mysql_query($sql);
//页面跳转,实现方式为javascript
$url = “list.php”;
echo “”;
echo “window.location.href=’$url'”;
echo “”;
}
?>
function checkPost(){
if(addForm.user.value==””){
alert(“请输入用户名”);
addForm.user.focus();
return false;
}
if(addForm.title.value.length<5){
alert(“标题不能少于5个字符”);
addForm.title.focus();
return false;
}
}
用户:
标题:
内容:
list.php
复制代码 代码如下:
include ‘conn.php’;
?>
echo “
“;
?>
$sql=”select * from message order by id”;
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query)){
?>
标题: 用户:
内容:
发表日期:
delete.php
复制代码 代码如下:
include ‘conn.php’;
$id = $_GET[‘id’];
$query=”delete from message where id=”.$id;
mysql_query($query);
?>
//页面跳转,实现方式为javascript
$url = “list.php”;
echo “”;
echo “window.location.href=’$url'”;
echo “”;
?>
preEdit.php
复制代码 代码如下:
include ‘conn.php’;
$id=$_GET[id];
$query=”SELECT * FROM message WHERE id =”.$id;
$result=mysql_query($query);
while ($rs=mysql_fetch_array($result)){
?>