当前位置:Gxlcms > PHP教程 > 一个简易需要注册的留言版程序_PHP

一个简易需要注册的留言版程序_PHP

时间:2021-07-01 10:21:17 帮助过:28人阅读

1.guestbook.php(留言程序)



天地网络留言版




$PAGESIZE=5;
$db=mysql_connect("localhost","root","");
mysql_select_db("lyanban",$db);
$result=mysql_query("SELECT * FROM message order by date desc",$db);
$rowcount=mysql_num_rows($result);
$PAGES=CEIL($rowcount/$PAGESIZE);
if($rowcount==0)
{echo "目前没有留言!欢迎您留言!";}

if($rownum == "")
{
$rownum = 1;

}
$AA=CEIL($rownum/5);
$i=0 ;
echo "";
echo "
";
while ($myrow=mysql_fetch_array($result)){
$i ;
if(($i>=$rownum)&&($i<$rownum 5)){
echo "
共有留言:$rowcount 条 共:$PAGES 页 现在是第 $AA 页
";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "
姓  名$myrow[username]
电子信箱$myrow[email]
公司主页$myrow[homepage]
留言主题$myrow[topic]
留言内容$myrow[content]
留言时间$myrow[date]

";}
}
echo "";
echo "";
echo "
";
#判断是否有上一页或下一页(10行换页)

echo "";
echo "
";
echo "
返回继续发言
";
?>


2.show.php3(显示程序)
?
$username = htmlspecialchars(ltrim(stripslashes (trim($name))));// 本函式可去掉字串中的反斜线空格字元
$email = htmlspecialchars(ltrim(stripslashes (trim($email))));
$homepage = htmlspecialchars(ltrim(stripslashes (trim($homepage))));
$topic = htmlspecialchars(ltrim(stripslashes (trim($topic))));
$content = htmlspecialchars(ltrim(stripslashes (trim($content))));
// $content=base64_encode($content);
//send email
// if ($ok) mail($email,$topic,$content);
if (($username=="")or($topic=="")or(strlen($username)>20)or(strlen($topic)>20))
{echo "请填写必要的项目或着非法用户名!返回";
}
//wrong email ?
elseif (($email!="")and(!eregi("^[_.0-9a-z-] @([0-9a-z][0-9a-z-] .) [a-z]{2,3}$",$email)))
{
echo "请您填写正确的 E-Mail 地址

返回";
}
//wrong homepage ?
elseif (($homepage!="")and(!eregi("(http://) [0-9a-z-] .([0-9a-z-] .) [a-z]{2,3}$",$homepage)))
{echo "主页地址输入错误!返回";}
else{
//联接数据库
mysql_connect("localhost","root","");
mysql_select_db("lyanban");
$sql="select password from tb where username='$username'";
$result=mysql_query($sql);
$nums=mysql_num_rows($result);
if($nums!=1){
echo"对不起!请先注册!";
}
else{
//得到日期 YYYY-MM-DD HH:MM:SS 2000-01-01 00:00:00'
$t = date(Y."-".m."-".d." ".H.":".i.":".s);
//将新用户插入数据库
mysql_query("insert into message values ('$username','$email','$homepage','$topic','$content','$t')");
echo "谢谢您留言!您的留言已成功加入,返回";
}
}
?>
3.zhuc.php(注册程序)
mysql_connect("localhost","root","")
or die("无法连接数据库,请重试");

mysql_select_db("lyanban")
or die("无法选择数据库,请重试");
$query="select password from tb where username='$username'";
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
if($numrows!=0)
{echo '已有人注册此名,请重新选择名字!返回';}
else
{$query="insert into tb(username,password) values('$username','$password')";
mysql_query($query);
echo '注册成功';
echo '请登录!';}
?>
以下是两个配套的HTML:
1。留言网页






天地网络留言版欢迎您留言!






天地网络留言版测试版






 


 






2.注册程序


registe







用户注册







如需要ZIP文件可给我来信。tandinet@163.net

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】

人气教程排行