【www.bbyears.com--留言】
/************/
config.php
/***********/
$host = "localhost"; // 数据库服务器
$user = "root"; // 数据库用户名
$password = "123456"; // 数据库密码
$db = "project"; // 数据库名
//打开数据库
$conn = mysql_pconnect ($host,$user,$password);
if(!$db)
{
die("数据库连接失败!");
}
//选择数据库
mysql_select_db ($db);
?>
/*********************/
index.php
/********************/
<script type="text/javascript">
function check_form(obj){
if(document.getElementById("post_name").value==""){
alert("写一下您的大名吧");
document.getElementById("post_name").focus();
return false;
}
if(document.getElementById("post_body").value==""){
alert("不是来捣乱的吧,写一下留言内容吧!");
document.getElementById("post_body").focus();
return false;
}
return true;
}
</script>
include("get.php")
?>
/***************************/
get.php
/****************************/
[quote]
include("config.php");
$query = "SELECT * FROM project_post";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) echo "姓名:$row[post_name] 内容: $row[post_body]";
?>
/***************************/
sent.php
/***************************/
include("config.php");
$post_name=addslashes($_POST["post_name"]);
$post_body=addslashes($_POST["post_body"]);
$sql = "INSERT INTO project_post (post_name,post_body) VALUES("$post_name","$post_body")";
mysql_query($sql);
header("location:/index.php");
?>