留言板

来源:互联网 发布:lofter独立域名 编辑:程序博客网 时间:2024/04/28 06:16

 

数据库前台

<html>
<title>留言板</title>
<body>

<table border="0" align="center">
<form id="form1" method="POST" action="add.php">
<tr>
用户名:<input id="user" type="text">
</tr>
<tr>
</tr>
<tr></tr>
标题:<input id="title" type="text">
<textarea name="content" ></textarea>
</tr>

<tr><td><input type="submit" value="提交"></td>
<td><input type="reset" value="重置"/></td></tr>
</form>
</table>
</body>
</html>

连接数据库

<?php
//建立数据库连接
$conn=@mysql_connect("localhost","root","123") or die ("数据库链接错误");
//选择数据库
mysql_select_db("data");
//没置编码
mysql_query("set names gbk");


?>

 

实现功能

<?php
include 'content.php';//链接数据库
//$id=$_POST['id'];
$user=$_POST['user'];
$title=$_POST['title'];
$content=$_POST['content'];
//$lastdate=$_POST['lastdate'];

$sql="insert into news values(null,".$user.",'".$title."','".$content."')'";

$rs=mysql_query($sql);
?>
<script tyle="text/javascript" language="javascript">
 function check(){

  if(document.form1.user.value=="0"){
   alert("请输入用户名及密码");
   return false;
  }
  else if(document.form1.title.value==""){
   alert("标题不能为空!"); 
   return false;
  }
  return true;
 }

</script>

 

 

 

 

 

原创粉丝点击