先建数据库表啊,前端用表单通过ajax提交数据。
你不是刚学完PHP吗?要想实现功能,就要知道实现功能需要些啥啊。
建议先找个框架学一学,比如ThinkPHP等。
下面是在csdn博客上找到的,作者是:topfzy
善用百度!!!!
//创建数据库
CREATE DATABASE GBOOK;
CREATE TABLE `gbook` (
`id` INT( 255 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 10 ) NOT NULL ,
`sex` TINYINT( 1 ) UNSIGNED NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`info` TEXT NOT NULL ,
`ip` VARCHAR( 15 ) NOT NULL ,
`time_at` DATETIME NOT NULL
)
主要页面有:
input.html为初始页
insert.php为把输入内容送入数据库
show.php显示留言板内容
change.php修改留言板内容的界面
del.php删除留言板内容
change_ok.php修改留言板内容并送入数据库
表单input.html页面:
留言版
数据库写入:insert.php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$ip = getenv('REMOTE_ADDR');
$conn = mysql_connect("localhost","root","123456");
mysql_select_db("gbook");
$sql = "INSERT INTO `gbook` ( `id` , `name` , `sex` , `email` , `info` , `ip` , `time_at` )
VALUES (NULL , '$name', '$sex', '$email', '$info', '$ip', NOW( ))";
$result = mysql_query($sql,$conn);
$id = mysql_insert_id();
mysql_close($conn);
?>留言成功
留言板内容展示:show.php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "SELECT * FROM gbook ORDER BY 'id' DESC"; //排序 后留言的在前面显示
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
while($row = mysql_fetch_row($result))
{ // ----if语句判断男女------
if($row[2]==1)
{ $gender = '男';}
else
{ $gender = '女'; }
?>
=$row[6]?> =$row[5]?> =$row[1]?>(=$gender?>) =$row[3]?> |
=nl2br($row[4])?> |
change.php修改留言板内容的界面
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "SELECT name, sex, email, info FROM gbook WHERE id = '$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
?>留言版
del.php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "DELETE FROM gbook WHERE id = '$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
mysql_close($conn);
?>
change_ok.php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "UPDATE `gbook` SET `name` = '$name',`sex` = '$sex',`email` = '$email',`info` = '$info' WHERE `id` ='$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
mysql_close($conn);
?>
要是详细介绍的话,你就按照功能划分就成.
像:注册功能, 登录功能,留言功能,查询功能,以及后台的管理功能.
介绍的时候,多介绍一下细节。像登录、注册、留言的时候如何防止sql注入。
至于规范 倒没有特定的格式,只要让人看明白就行
我建议哈,不要写具体的项目了,直接一笔代过,写成:独立编写过中小型PHP程序。因为留言板确实太基础了。