共计 2602 个字符,预计需要花费 7 分钟才能阅读完成。
涉及到 (java 验证,区块链宠物系统 APP 开发(T:I8O、2853、296O V 黎灿)str_replace,md5 cookie htmspecialchar)
源码:
PHP&Mysql 简单留言板 (java 验证,str_replace,md5 cookie htmspecialchar)
sql:
CREATE TABLE message
(
id
tinyint(2) 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
)
)ENGENE=InnoDB DEFAULT CHARSET=gbk_chinese_ci AUTO_INCREMENT=1;
Conn.php
<?php
$conn = @mysql_connect(“localhost”,”root”,”2311220″);
mysql_select_db(“newdb”,$conn);
mysql_query(“set names ‘utf8_general_ci'”);
function htmocode($content){
$content =str_replace("\n","<br>",str_replace(""," ",$content));
return $content;
}
?>
Head.php
<head>
<meta http-equiv=”Content-Type” content=”text/html” ; charset=utf8_general_ci” >
<title></title>
<link href=”image/css.css” rel=”stylesheet” type=”text/css”>
添加留言 | 浏览留言 | 登陆
</head>
List.php
<?php
include(“head.php”);
include(“conn.php”);
?>
标题:<?php echo $row[title]?> 用户:<?php echo $row[user]?> |
内容:<?php echo htmocode($row[content])?> |
Add.php
<?php
include(“head.php”);
include(“conn.php”);
if($_POST[‘submit’]){
$sql=”insert into message(id,user,title,content,lastdate) “.
"values('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo “<script language=”javascript”>alert(‘ 添加成功 ’);history.go(-1)</script>”;
}
?>
<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();
return false;
}
}
</SCRIPT>
<form action=”add.php” method=”post” name=”myform” onsubmit=”return CheckPost()”>
用户:<input type=”text” name=”user” />
标题:<input type=”text” name=”title”/>
内容:
<textarea name=”content”></textarea>
<input type=”submit” name=”submit” value=” 发表留言 ” />
</form>
数据库
Login.php
<?php
include(“head.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>";
}
}
if($_COOKIE[‘cookie’]!=ok){
?>
<SCRIPT language=”javascript”>
function CheckLogin()
{
if(myform.id.value=="")
{alert("请填写用户名");
myform.user.focus();
return false;
}
if(myform.pw.value=="")
{alert("密码不能为空!");
myform.title.focus();
return false;
}
}
</SCRIPT>
<form action=”” method=”post” name=”myform” onsubmit=”return CheckLogin()”>
ID: <input type=”text” name=”id” />
PW: <input type=”password” name=”pw” />
<input type=”submit” name=”submit” value=” 登陆 ”/>
</form>
<?php }else {?>
退出
<?php }?>