php学习笔记(12):PHP+MYSQL留言板(下
来源:互联网 发布:2016小米手机抢购软件 编辑:程序博客网 时间:2024/05/16 08:44
1、提交表单Javascript验证
<form action="" method="post" name="myform" onsubmit="return CheckPost();">
SCRIPT language=javascript>
function CheckPost()
{
if (myform.user.value=="")
{
alert("请填写用户");
myform.user.focus();
return false;
}
if (myform.title.value.length<5)
{
alert("标题不能少于5个字符");
myform.title.focus();
……
}
2、str_replace替换函数
替换的值,被替换的内容);
function htmtocode($content) {
$content = str_replace("/n", "<br>", str_replace(" ", " ", $content));
return $content;
}
3、htmlspecialchars 格式化html
主要功能是将HTML格式化,防止在输出html时被浏览器执行
htmlspecialchars(所要格式化对象,定义单双引号,编码)
4、md5加密函数
md5( 加密对象 )
hearder.php:
add.php:
<html>
<head>
<title>添加页面</title>
<style type="text/css">
body{font-size:12px;text-align:center;}
#capation{font-size:24px;font-famliy:"华文新魏";}
</style>
<script type="text/javascript">
function ClearInputWords(){
document.myForm[0].value="";
document.myForm[1].value="";
document.myForm[2].value="请在此输入您的留言!";
}
function CheckInput(){
var user=document.myForm["user"].value;
var title=document.myForm["title"].value;
var content=document.myForm["content"].value;
if(user==""){
alert("用户不能为空!");
document.myForm[0].focus();
return false;
}
if(title==""||title.length<2){
alert("标题不能为空且长度不能小于2个字符");
document.myForm[1].focus();
return false;
}
if(content==""){
alert("内容不能为空!");
document.myForm[2].focus();
return false;
}
}
</script>
</head>
<body>
<?php
/*
* Created on 2010-1-5
* Author:CHAVUET
* Function:留言板
*/
include("header.php");
?>
<span id="capation">添加留言</span>
<form action="conn.php" method="post" name="myForm" onsubmit="return CheckInput()">
<table>
<tr>
<td>用户:</td>
<td><input type="text" name="user" size="12"/></td>
</tr>
<tr>
<td>标题:</td>
<td><input type="text" name="title" size="18"/></td>
</tr>
<tr>
<td valign="top">内容:</td>
<td><textarea name="content" cols="24" rows="5">请在此输入您的留言!</textarea></td>
</tr>
<tr>
<td colspan="2"> <input type="submit" name="submit" value="提交留言"/>
<input type="button" value="重置" onclick="ClearInputWords()"></td>
</tr>
</table>
</form>
</body>
</html>
conn.php:
<?php
/*
* Created on 2010-1-4
* Athor: CHAUVET
* Function:处理页面,对数据库操作
*/
if($_POST['submit']!=null){
$conStr=mysql_connect("localhost","root","") or die("连接数据库失败!!!");
mysql_select_db("newdb",$conStr);
mysql_query("set names 'gb2312'");
$str="insert into Message values('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($str);
unset($str);
mysql_close($conStr);
}
header("location:list.php");
?>
list.php:
<html>
<?php
/*
* Created on 2010-1-4
* Author: CHAUVET
* Function:显示用户留言
*/
include("header.php");
$conStr=mysql_connect("localhost","root","") or die("连接数据库出错!");
mysql_select_db("newdb",$conStr);
mysql_query("set names 'gb2312'");
$result=mysql_query("select * from Message");
mysql_close($conStr);
?>
<body>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef" style="margin-top:40px;">
<? while($row=mysql_fetch_array($result)){?>
<tr style="background-color:#eff3ff">
<td>用户:<?=$row["USER"]?> 标题:<?=$row["TITLE"]?></td>
</tr>
<tr style="background-color:#80FF80">
<td>时间:<?=$row["LASTDATE"]?></td>
</tr>
<tr style="background-color:#ffffff">
<td>内容:<?= ReplaceSomeWords($row["CONTENT"])?></td>
</tr>
<? } ?>
</table>
</body>
</html>
login.php:
<?php
include("conn.php");
if($_GET[out]){
setcookie("cookie", "out");
echo "<script language=/"javascript/">location.href='login.php';</script>";
}
if($_POST[id]=='admin'){
$pw=md5($_POST[pw]);
if($pw=='e1bfd762321e409cee4ac0b6e841963c'){
setcookie("cookie", "ok");
echo "<script language=/"javascript/">location.href='login.php';</script>";
}
}
include("head.php");
if($_COOKIE['cookie']!='ok'){
?>
<SCRIPT language=javascript>
function Checklogin()
{
if (myform.id.value=="")
{
alert("请填写登录名");
myform.id.focus();
return false;
}
if (myform.pw.value=="")
{
alert("密码不能为空");
myform.pw.focus();
return false;
}
}
</SCRIPT>
<form action="" method="post" name="myform" onsubmit="return Checklogin();">
ID:<input type="text" name="id" /><br>
PW:<input type="password" name="pw" /> <input type="submit" name="submit" value="登陆"/>
</form>
<?
}else{
?>
<a href='?out=login'>退出</a>
<?
}
?>
- php学习笔记(12):PHP+MYSQL留言板(下
- php学习笔记(12):PHP+MYSQL留言板(上
- 我的php学习笔记(九)学习php+MySQL留言板(下)
- php留言板(下)
- 我的php学习笔记(八)学习制作php+MySQL留言板(上)
- PHP学习笔记(四)极简留言板
- php学习笔记之留言板制作
- php+mysql 留言板
- php +mysql 留言板 1
- php & mysql 留言板 3
- php mysql 留言板 4
- 留言板--PHP+MySQL开发
- linux php mysql 留言板
- PHP+Mysql 实现留言板
- php+mysql制作留言板
- PHP+Mysql 实现留言板
- php +mysql 留言板
- PHP&MYSQL留言板源码
- 某网站品牌列表效果
- 关于波斯历(奇怪的历法)
- iPhone解析非UTF-8的XML
- CreateEvent 函数用法
- VC字符串函数大全
- php学习笔记(12):PHP+MYSQL留言板(下
- 简单的c数字程序
- c/c++ 后缀名详解
- repeater控件嵌套实现系统/网站导航
- 车开了五天了!
- 开心是个传说
- 伊朗曆
- VC 查找进程,关闭进程
- Ubuntu安裝 SVN