|
項(xiàng)目結(jié)構(gòu):
添加頁(yè)面: 說(shuō)明:這里只注重操作,對(duì)界面的美工沒(méi)有下工夫,希望大家理解......
列表頁(yè)面:
修改頁(yè)面:
項(xiàng)目中所需的sql:
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("數(shù)據(jù)庫(kù)鏈接錯(cuò)誤");
mysql_select_db("form", $conn);
mysql_query("set names 'gbk'");
?>
add.php
復(fù)制代碼 代碼如下:
<?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);
//頁(yè)面跳轉(zhuǎn),實(shí)現(xiàn)方式為Javascript
$url = "list.php";
echo "<script language='Javascript' type='text/Javascript'>";
echo "window.location.href='$url'";
echo "</script>";
}
?>
<script type="text/Javascript">
function checkPost(){
if(addForm.user.value==""){
alert("請(qǐng)輸入用戶名");
addForm.user.focus();
return false;
}
if(addForm.title.value.length<5){
alert("標(biāo)題不能少于5個(gè)字符");
addForm.title.focus();
return false;
}
}
</script>
<FORM name="addForm" METHOD="POST" ACTION="add.php" onsubmit="return checkPost();">
用戶:<INPUT TYPE="text" NAME="user" /><br />
標(biāo)題:<INPUT TYPE="text" NAME="title" /><br />
內(nèi)容:<TEXTAREA NAME="content" ROWS="8" COLS="30"></TEXTAREA><br />
<INPUT TYPE="submit" name="submit" value="add" /></FORM>
list.php
復(fù)制代碼 代碼如下:
<?php
include 'conn.php';
?>
<?php
echo "<div align='center'><a href='add.php'>繼續(xù)添加</a></div>";
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?php
$sql="select * from message order by id";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query)){
?>
<tr bgcolor="#eff3ff">
<td>標(biāo)題:<font color="red"><?=$row[title]?></font> 用戶:<font color="red"><?=$row[user] ?></font><div align="right"><a href="preEdit.php?id=<?=$row[id]?>">編輯</a> | <a href="delete.php?id=<?=$row[id]?>">刪除</a></div></td>
</tr>
<tr bgColor="#ffffff">
<td>內(nèi)容:<?=$row[content]?></td>
</tr>
<tr bgColor="#ffffff">
<td><div align="right">發(fā)表日期:<?=$row[lastdate]?></div></td>
</tr>
<?php }?>
</table>
delete.php
復(fù)制代碼 代碼如下:
<?php
include 'conn.php';
$id = $_GET['id'];
$query="delete from message where id=".$id;
mysql_query($query);
?>
<?php
//頁(yè)面跳轉(zhuǎn),實(shí)現(xiàn)方式為Javascript
$url = "list.php";
echo "<script language='Javascript' type='text/Javascript'>";
echo "window.location.href='$url'";
echo "</script>";
?>
preEdit.php
復(fù)制代碼 代碼如下:
<?php
include 'conn.php';
$id=$_GET[id];
$query="SELECT * FROM message WHERE id =".$id;
$result=mysql_query($query);
while ($rs=mysql_fetch_array($result)){
?>
<FORM METHOD="POST" ACTION="postEdit.php">
<input type="hidden" name="id" value="<?=$rs[id]?>">
用戶:<INPUT TYPE="text" NAME="user" value="<?=$rs[user]?>"/><br />
標(biāo)題:<INPUT TYPE="text" NAME="title" value="<?=$rs[title]?>"/><br />
內(nèi)容:<TEXTAREA NAME="content" ROWS="8" COLS="30"><?=$rs[content]?></TEXTAREA><br />
<INPUT TYPE="submit" name="submit" value="edit"/>
</FORM>
<?php }?>
postEdit.php
復(fù)制代碼 代碼如下:
<?php
include 'conn.php';
$query="update message set user='$_POST[user]',title='$_POST[title]',content='$_POST[content]' where id='$_POST[id]'";
mysql_query($query);
?>
<?php
//頁(yè)面跳轉(zhuǎn),實(shí)現(xiàn)方式為Javascript
$url = "list.php";
echo "<script language='Javascript' type='text/Javascript'>";
echo "window.location.href='$url'";
echo "</script>";
?>
php技術(shù):php開(kāi)發(fā)留言板的CRUD(增,刪,改,查)操作,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。