⑴ 解释分析php留言板代码 急!好的 详细的加高分!
呼呼,给你几乎每一句都注释了
<form action="#" method="post"
enctype="multipart/form-data">
name<input name=name >sex<input name=sex >age<input name=age >QQ<input name=qq >
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
<!--以上为留言板的留言表单-->
<?php
$host="localhost";
$user="root";
$password="";
$db="testdb";
$con=@mysql_connect($host,$user,$password); //不报错创建与mysql数据库服务器的连接
if(!mysql_select_db($db)){ //选择服务器数据库
echo "没有相应数据库,正在给你创键"; //如果数据库不存在
mysql_query("CREATE DATABASE `testdb` DEFAULT CHARACTER SET gb2312 COLLATE gb2312_chinese_ci;"); //创建一个名为textdb的数据库,使用gb2312字符集
mysql_query("CREATE TABLE `testdb`.`book` ( //一下为在textdb下创建book数据表
`name` VARCHAR( 20 ) NOT NULL , //表列name,为20字符以内的非空字符串
`sex` VARCHAR( 3 ) NOT NULL , //表列sex,为3字符以内的非空字符串
`age` INT( 3 ) NOT NULL , //表列age,为3位以内的整数
`time` VARCHAR( 20 ) NOT NULL , //表列time,为20字符以内的非空字符串
`qq` VARCHAR( 15 ) NOT NULL , //表列qq,为15字符以内的非空字符串
`url` VARCHAR( 30 ) NOT NULL , //表列url,为30字符以内的非空字符串
PRIMARY KEY ( `name` ) //创建关键索引name
) ENGINE = MYISAM;"); //使用MYISAM数据库系统
echo "成功创建!";
}
if(!file_exists("up")) //如果up文件夹不存在
{
mkdir("up",0777); //创建文件夹up,为全体可读写执行
@chmod("up",0777); //不报错改变文件夹up为全体可读写执行
}
$name=split("\.",$_FILES["file"]["name"]); //用“.”分割上传的文件名字,返回一个数组
$counter=count($name)-1; //给$counter赋值$name数组的个数减一
$pre=$name[count($name)-1]; //给$pre赋值$name数组的最后一位(也就是文件扩展名,不含“.”)
$dastr=date("YmdHis"); //给$dastr赋值当前时间(格式为:年月日时分秒)
if (file_exists("up/" . $_FILES["file"]["name"])) //如果up文件夹中有与上传的文件重名的文件
{
echo $_FILES["file"]["name"] . " already exists. "; //输出文件已存在
}
else //否则
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"up/" . $dastr.'.'.$pre); //将上传的文件从临时缓存移动到up文件夹当中并改名为“日期.扩展名”
}
$name=$_POST['name']; //给$name赋值为表单中name输入框的内容
$age=$_POST['age']; //给$age赋值为表单中age输入框的内容
$sex=$_POST['sex']; //给$sex赋值为表单中sex输入框的内容
$qq=$_POST['qq']; //给$qq赋值为表单中qq输入框的内容
$url="up/" . $dastr.'.'.$pre; //给$url赋值为上传文件的地址
$time=date("Y-m-d H:i:s"); //给$time赋值为当前时间(格式:年-月-日 时:分:秒)
mysql_query("set names gb2312"); //设置字符集,解决中文乱码问题
mysql_select_db($db); //选择数据库
$exec="insert into book (name,age,sex,qq,time,url) values ('$name','$age','$sex','$qq','$time','$url')";
//给$exec赋值向book表中添加数据的命令字符串
if($name!=''){ //如果$name不是空
$result=mysql_query($exec); //执行$exec的命令
}
$sql="select * from book"; //给$sql赋值选取book当中的所有列和行的命令的字符串
$result=mysql_query($sql); //执行$sql语句,返回结果
while($rs=mysql_fetch_object($result)) //遍历所有结果(循环直到所有$result当中的结果都以输出)
{
echo "<div class=result><ul><li>用户名:".$rs->name."</li>\n"; //一下为输出留言内容
echo "<li>年领:".$rs->age."</li>\n";
echo "<li>年领:".$rs->sex."</li>\n";
echo "<li>QQ:".$rs->qq."</li>\n";
echo "<li>头像: <img src=".$rs->url." /></li>\n";
echo "<li>留言时间:".$rs->time."</li></ul></div>\n";
}
mysql_close(); //关闭与数据服务间的连接
?>
⑵ 新手刚学ThinkPHP 网上找的都是3.1版本的,改动很大。ThinkPHP3.2 留言板源码 求学习
程序都一样的。。 改的也是一部分,多练练,就可以啦。
⑶ 急求一个PHP的简单的留言板,输入临时名字 然后输入留言提交就可以显示在页面的
<?php
include 'conn.php'
$action = $_GET['action'];
$user=str_replace(" ","",$_POST[textfield]);
if($_POST['Submit2']){
if(!empty($_POST[textfield])){
$user=str_replace(" ","",$_POST[textfield]);
$password=str_replace(" ","",$_POST[textfield2]);
$user1=md5($user);
$password1=md5($password);
function userlogin($user1)
{
global $manager;
$sql="select * from $manager where user='$user1'";
//$sql="insert into manager (user,password) values ('$user','$password');";//用于插入需要的管理员用户信息
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
return $row;
}
$row=userlogin($user1);
if($row){
$ps=$password1==$row[password];
}else{
$ps=FALSE;
// echo "<script type="text/javascript">alert("用户名错误")</script>";
}
if($ps){
$_SESSION[uid]=$user;
$_SESSION[upass]=$row[password];
header("Location:index.html");
}else{
$b=FALSE;
echo "<script type="text/javascript">alert("用户名或者密码错误")</script>";
echo '<script language="JavaScript">window.location.href="login.html";</script>'
}
}else{
echo "<script type="text/javascript">alert("用户名不能为空格")</script>";
echo '<script language="JavaScript">window.location.href="login.html";</script>'
}
}
?>
以上是userlogin.php文件,其中引用的conn.php文件代码如下:
其中数据库自己建一个,注册页面大体也相同,你理解了这个,就自己能写注册页面了
<?php
@header('Content-Type: text/html; charset=utf-8');
@session_start();
$conn = @ mysql_connect("127.0.0.1", "zznt", "19880210") or die("数据库连接错误");
mysql_select_db("zznt", $conn);
//mysql_query("set NAMES 'utf8'");
//mysql_query("set character_set_client=utf8");
//mysql_query("set character_set_results=utf8");
mysql_query("set NAMES 'utf8'");
mysql_query("set character_set_client=utf8");
mysql_query("set character_set_results=utf8");
//$content=str_replace("'","钬?,$content);
//htmlspecialchars();
?>
⑷ 求php语言编写的留言板源码!!!!!!!!!
这是一个简单的留言本,目前还没有后台管理程序。如果哪位高手能补上,那就太好了。
演示在http://www.ideawu.net/person/liuyan
留言保存在message.txt文件中,留言的格式为:date<$>ip<$>name<$>content
"<$>"为分隔符号
注意:源码文件和message.txt文件必须以gbk格式保存。如果你不知道如何保存文件为gbk格式,请咨询你的文本编辑器软件提供商。
/****************************************
* 本代码可以用作任何用途,但是与作者无关。
* 也就是,你使用本代码获取收益或者因此受
* 到损害,后果与作者无关。
****************************************/
file: index.php
代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>留言板</title>
<link rel="stylesheet" href="../msg.css" type="text/css">
</head>
<body>
<br><B><FONT COLOR="#0000FF">图片留言板</FONT></B>
<center>
<table width="800" border="1" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all">
<tr><td style="border-right-style: none">
<form method="post" action="savemsg.php" style="font-size: 13px">
姓名:<br><input type="text" name="guest_name" maxlength=32 size=32><br>
留言:(字数:<font color="#0000FF"><span id=sNum>0</span></font>/256)<br>
<textarea class="textForm" name="guest_msg" cols="64" rows="8" onkeyup="sNum.innerHTML=this.value.length"></textarea><br>
<input class="button" type="submit" name="submit" value="发表留言">
<input class="button" type="reset" value="重置" name="reset">
</form>
</td></tr>
</table>
<?php
include("showmsg.php");
if(!empty($_GET['p'])){
$num=$_GET['p'];
showpage($num);
}else showpage(1);
?>
</center>
</body>
</html>
file: showmsg.php
代码:
<?php
function showpage($p)
{ ?>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all;font-size:12px;">
<tr><td>
<p style="line-height: 100%; margin-top: 1; margin-bottom: 1" align="left">
<?php
$perPage=7; //每页显示留言数目
$num=$p;
if($num<1) $num=1;
$prev=$num-1;
$next=$num+1;
$page=$num-1; //当前页码
$fname="message.txt"; //存储留言的文件
$all_msg=file($fname); //将留言读入数组
$line_count=count($all_msg);
$page_count=ceil($line_count/$perPage);
if($prev>0)
echo "<a href=index.php?p=$prev>上一页</a>";
else
echo "上一页";
if($line_count>($next-1)*$perPage)
echo "<a href=index.php?p=$next>下一页</a>";
else
echo "下一页";
echo "当前第 ".$num." 页,共有".$page_count."页,".$line_count."条留言。";
?>
</p></td></tr>
</table>
<table width="800" border="1" bordercolor="#88CCEE" cellpadding="3" cellspacing="0" style="border-collapse:collapse; font-size:12px; word-break:normal; table-layout:fixed;">
<tr height="18" bgcolor="#5FBEF8"><td width="20%">
<b>留言时间/留言者</b></td><td width="86%"><b>留言内容</b>
</td></tr>
<?php
//显示留言
$bg1="#FBF9F9"; $bg2="#E9EFF4";$bg=$bg2;
for($n=$line_count-1-$page*$perPage;$line_count-1-$page*$perPage-$n<$perPage;$n--){
$bg=($bg==$bg1)? $bg2:$bg1; //变换背景颜色
if(!empty($all_msg[$n])){
list($date,$ip,$name,$msg)=explode("<$>",$all_msg[$n],4); //获取留言内容
echo "<tr bgcolor=$bg>";
echo "<td width=14%>".$date."<br><b>".$name."</b></td>";
echo "<td width=86%>".$msg."</td>";
echo "</tr>";
}
}
?>
</table>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all;font-size:12px">
<tr><td>
<p style="line-height: 100%; margin-top: 2; margin-bottom: 2" align="left">
<?php
if($prev>0)
echo "<a href=index.php?p=$prev>上一页</a>";
else
echo "上一页";
if($line_count>($next-1)*$perPage)
echo "<a href=index.php?p=$next>下一页</a>";
else
echo "下一页";
echo "当前第 ".$num." 页,共有".$page_count."页,".$line_count."条留言。";
?>
</p></td></tr>
</table>
<?php } ?>
file: savemsg.php
代码:
<?php
$MSG_MAX_LEN=512; //留言最大长度
if (getenv("HTTP_CLIENT_IP"))
$ip= getenv("HTTP_CLIENT_IP");
elseif (getenv("HTTP_X_FORWARDED_FOR"))
$ip= getenv("HTTP_X_FORWARDED_FOR");
else
$ip= getenv("REMOTE_ADDR");
//获取IP地址结束
$date=date("Y年m月d日 H:i:s",time());
if(empty($_POST['guest_name']))
die("请填你的名字。<a href=index.php>Refresh</a>");
if(empty($_POST['guest_msg']))
die("请填写留言内容再提交。<a href=index.php>Refresh</a>");
$guest_name=strip_tags($_POST['guest_name']);
$guest_msg=substr($_POST['guest_msg'],0,$MSG_MAX_LEN);
//write message to file
//make the message be a line when stored
$guest_msg = str_replace( "\r\n", "\n", $guest_msg);
$guest_msg = str_replace( "\r", "\n", $guest_msg);
$guest_msg = str_replace(" "," ",$guest_msg);
$guest_msg = str_replace(">",">",$guest_msg);
$guest_msg = str_replace("<","<",$guest_msg);
$guest_msg = str_replace("\'","'",$guest_msg);
$guest_msg = nl2br($guest_msg);
//保存留言,以追加的形式
$fname="message.txt";
$fp=fopen($fname,"a+");
fwrite($fp,$date."<$>".$ip."<$>".$guest_name."<$>".$guest_msg."\n");
fclose($fp);
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
?>
用于显示效果的样式表文件
file: msg.css
代码:
A:link {
color: #0033FF;
text-decoration: none;
}
A:visited {
color: #0033FF;
text-decoration: none;
}
A:hover {
color: #30A300;
text-decoration: underline;
}
A:active {
color: #0036A9;
text-decoration: none;
}
BODY{
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 12px;
background: #FBF9F9;
}
TABLE{
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 12px;
border-collapse: collapse;
table-layout: fixed;
margin: 0px;
}
⑸ 求php语言编写的留言板源码!!!!!!!!!
这是一个简单的留言本,目前还没有后台管理程序。如果哪位高手能补上,那就太好了。
演示在
http://www.ideawu.net/person/liuyan
留言保存在message.txt文件中,留言的格式为:date<$>ip<$>name<$>content
"<$>"为分隔符号
注意:源码文件和message.txt文件必须以gbk格式保存。如果你不知道如何保存文件为gbk格式,请咨询你的文本编辑器软件提供商。
/****************************************
*
本代码可以用作任何用途,但是与作者无关。
*
也就是,你使用本代码获取收益或者因此受
*
到损害,后果与作者无关。
****************************************/
file:
index.php
代码:
留言板
<b>
图片留言板</b>
<table
width="800"
border="1"
bordercolor="#88CCEE"
cellspacing="0"
cellpadding="4">
<tr><td>
</td></tr>
</table>
file:
showmsg.php
代码:
&l
⑹ 留言板PHP和mysql源码
保存可以用txt或者mysql方式保存。如果你是刚学习可以用txt,
采用post方式提交后用$_POST['content']获取到内容后用fwrite按格式写到一个文件里,可以一行一个,读取的时候用fgets读取每行的内容,然后调用变量显示到标签里
<?php
if(isset($_POST['content'])){
$fp=fopen('talk.txt','w+');
fwrite($fp,$_POST['content']." ");
fclose($fp);
exit("提交成功");
}else{
echo'<formmethod="post"><textarearows="3"name="content"placeholder="请输入内容"></textarea><br/><inputtype="submit"value="留言"/></form>';
$fp=@fopen("/tmp/inputfile.txt","r");
if($fp){
while(!feof($fp)){
$buffer=fgets($fp);
echo$buffer."<br>";//显示每行内容
}
fclose($fp);
}else{
echo"打开文件失败或者文件不存在";
}
}
?>
纯手打,请采纳
⑺ 本人PHP新手. 需要PHP源码. ................~~~~~~~~~
PHP是C语言系列语言~~是网页动态语言~~基础的看完了~~如果你依然不懂得如何制作~~只能说明你还是没有完全的看懂~~PHP的动态主要就在于一个反馈~~用户与服务器之间的反馈~~反馈的方式有POST与GET两种~~记录传递信息的有COOKIE与SESSION两种~~这两点如果看懂了~~其他的就和C区别不是很大了~~
如果你需要HTML与PHP混合编写~~可以考虑在html语句中添加PHP~~例如:<a href="<?php echo "#"; ?>"></a>的方式~~也可以在PHP中添加HTML,例如<?php echo "<a href=\"#\">"; ?>。希望对你有所帮助~~
⑻ 谁有好用的PHP源码留言簿
请到下面地址下载:
http://down.chinaz.com/soft/3337.htm
⑼ 最简单php留言板源码。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<BR><BR>
<center><a href="admin_login.htm" target="_blank">留言管理</a> </center><BR><BR>
<br><br><br>
<form method="post" >
<p>姓名:
<input type="text" name="user_name" size="20">
</p>
<p><br>
电话:
<input type="text" name="user_tel" size="20">
</p>
<p><br>
留言:
<textarea name="user_post" rows="5" cols="20"></textarea>
</p>
<p>
<input type="submit" value="提交留言" name="Submit">
</p>
</form>
<br><br><br>
<font color="red">最新留言如下:<BR><BR></font>
<?php
if($_POST['Submit']){
$user_name=$_POST['user_name'];
$user_tel=$_POST['user_tel'];
$user_post=$_POST['user_post'];
$ah=$_POST['ah'];
$where=$_POST['where'];
$str.="姓名:".$user_name."\r\n电话:".$user_tel."\r\n留言:".$user_post;
$k=fopen("liuyanban.txt","w+");
fwrite($k,$str);
fclose($k);
echo "保存成功!";
}
?>
</body>
</html>
⑽ 谁能提供一个PHP留言板源码
input.htm
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>input</title>
</head>
<body>
<form method="POST" action="receive.php">
<p>您的姓名: <input type="text" name="T1" size="20"></p>
<p>您的性别:男<input type="radio" value="0" name="R1">
女<input type="radio" name="R1" value="1"></p>
<p>您的EMAIL:<input type="text" name="T2" size="35"></p>
<p>您的留言内容:</p>
<p><textarea rows="16" name="S1" cols="45"></textarea></p>
<p> </p>
<p><input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
receive.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$ip=getenv(REMOTE_ADDR);
$sql = "INSERT INTO `guestbook`.`gbook` (`id`, `name`, `sex`, `email`, `info`, `ip`, `time_at`) VALUES (NULL, '$T1', '$R1', '$T2', '$S1', '$ip', NOW());";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
mysql_query($sql);
$result=mysql_query("select * from $table");
while ($arr=mysql_fetch_array($result))
{
if ($arr[2]==0)
$gender='先生';
else
$gender='女士';
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Receive</title>
</head>
<body style="background-attachment: fixed">
<table border="1" width="100%" id="table1" bgcolor="#FFFFFF">
<tr>
<td bordercolor="#FFFFFF" bgcolor="#C0C0C0"><?=$arr[6]?>(<?=$arr[5]?>)<p><?=$arr[1]?> <?=$gender?><<a href="<?=$arr[3]?>"><?=$arr[3]?></a>>
写到:</td>
</tr>
<tr>
<td><?=$arr[4]?><p> </p>
<p><a href="del.php?id=<?=$arr[0]?>">[删除]</a>
<a href="modify.php?id=<?=$arr[0]?>">[修改]</a>]</td>
</tr>
</table>
</body>
</html>
<?php
echo '<p>';
echo '<p>';
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<p><a href="input.htm"><继续留言></a></p>
</body>
</html>
del.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$sql="DELETE FROM $table WHERE id=$id";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query($sql);
if ($result)
echo "删除成功";
else
echo "删除失败";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<p><a href="receive.php"><返回首页></a></p>
</body>
</html>
modify.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$ip=getenv(REMOTE_ADDR);
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query("select * from $table where id=$id");
$arr=mysql_fetch_array($result);
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>input</title>
</head>
<body>
<form method="POST" action="modify_ok.php?id=<?=$id?>">
<p>您的姓名: <input type="text" name="T1" size="20" value="<?=$arr[1]?>"></p>
<p>您的性别:
<?php
if ($arr[2]==0) echo '男<input type="radio" value="0" name="R1" checked>
女<input type="radio" name="R1" value="1"></p>';
else echo '男<input type="radio" value="0" name="R1">
女<input type="radio" name="R1" value="1" checked></p>';
?>
<p>您的EMAIL:<input type="text" name="T2" size="35" value="<?=$arr[3]?>"></p>
<p>您的留言内容:</p>
<p><textarea rows="16" name="S1" cols="45" ><?=$arr[4]?></textarea></p>
<p> </p>
<p><input type="submit" value="修改" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
modify_ok.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);;
$sql = "UPDATE `guestbook`.`gbook` SET `name` = '$T1', `sex` = '$R1', `email` = '$T2', `info` = '$S1' WHERE `gbook`.`id` = '$id' LIMIT 1;";
$result=mysql_query($sql);
if ($result)
echo "修改成功";
else
echo "修改失败";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<p><a href="input.htm"><继续留言></a></p>
</body>
</html>