php留言板
/************/
config.php
/***********/
<?php
$host = 'localhost'; // 数据库服务器
$user = 'root'; // 数据库用户名
$password = '123456'; // 数据库密码
$db = 'project'; // 数据库名
//打开数据库
$conn = mysql_pconnect ($host,$user,$password);
if(!$db)
{
die('<b>数据库连接失败!</b>');
}
//选择数据库
mysql_select_db ($db);
?>
/*********************/
index.php
/********************/
<html>
<body>
<script type="text/javascript">
function check_form(obj){
if(document.getElementById('post_name').value==''){
alert('写一下您的大名吧');
document.getElementById('post_name').focus();
return false;
}
if(document.getElementById('post_body').value==''){
alert('不是来捣乱的吧,写一下留言内容吧!');
document.getElementById('post_body').focus();
return false;
}
return true;
}
</script>
<form action="/sent.php" method="post" onSubmit="return check_form(this)">
<table width="100%" border="0">
<tr>
<td align="right">您的大名</td>
<td><input name="post_name" id="post_name" type="text" size="20" maxlength="20"></td>
</tr>
<td align="right">您的发言</td>
<td><textarea name="post_body" id="post_body" rows="10" cols="50">您的发言</textarea></td>
<tr>
<td align="right"> </td>
<td><input type="submit" name="Submit" value="提 交" ></td>
</tr>
</table>
</form></td>
</body>
<html>
<?php
include('get.php')
?>
/***************************/
get.php
/****************************/
[quote]
<?php
include('config.php');
$query = "SELECT * FROM project_post";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) echo "姓名:$row[post_name] </br> 内容: $row[post_body]</br>";
?>
/***************************/
sent.php
/***************************/
<?php
include('config.php');
$post_name=addslashes($_POST['post_name']);
$post_body=addslashes($_POST['post_body']);
$sql = "INSERT INTO project_post (post_name,post_body) VALUES('$post_name','$post_body')";
mysql_query($sql);
header('location:/index.php');
?>
<?php
class conn{
function __construct(){
require("config.php");
$conn = @mysql_connect($host,$root,$pass);
@mysql_select_db($db);
if(!$conn){
echo "无法连接".mysql_errno() . ":" . mysql_error() ;
exit;
}
}
function query($sql){
$result = @mysql_query($sql);
if (!$result) {
echo mysql_errno().":".mysql_error();
exit;
}
return $result;
}
function next($result){
return @mysql_fetch_array($result);
}
function count_row($result){
$row = @mysql_num_rows($result);
return $row;
}
function close($result){
@mysql_free_result($result);
@mysql_close();
}
}
class fenye extends conn{
public $sql;
public $page;
public $countpage;
public $pagesize;
public $result;
function __construct($sql,$page,$pagesize){
$this->sql = $sql;
$this->page = $page;
$this->countpage = $countpage;
$this->pagesize = $pagesize;
parent::__construct();
$result = parent::query($sql);
$num = parent::count_row($result);
$this->countpage = ceil($num/$pagesize);
$a = ($page-1)*$pagesize;
$limit = "limit $a,$pagesize";
$this->sql = $sql.$limit;
$this->result = parent::query($this->sql);
}
function getlimit(){
return $this->sql;
}
function next(){
return parent::next($this->result);
}
function foor(){
$a = $this->page -1;
$b = $this->page +1;
if ($this->page == 1) {
echo "首页"." ";
}else echo "<a href='?page=1'>首页</a>"." ";
if($this->page >1)
echo "<a href='?page=$a'>上页</a>"." ";
else echo "上页 ";
for ($i =1;$i <= $this->countpage;$i++){
echo "<a href='?page=$i'>$i</a>"." ";
}
if($this->page < $this->countpage)
echo "<a href='?page=$b'>下页</a>"." ";
else echo "下页 ";
if ($this->page == $this->countpage) {
echo "末页"." ";
}else echo "<a href='?page=$this->countpage'>末页</a>";
#######################
}
}
####################
if (isset($_GET['page'])) {
$page = $_GET['page'];
}else $page = 1;
$sql = "select * from guestbook ";
$pagesize =3;
$p = new fenye($sql,$page,$pagesize);
$sql = $p->getlimit();
$result = $p->query($sql);
while($row = $p->next()){
echo $row['id']."<br>";
}
$p->foor();
$p->close($result);
?>
ServerAdmin host@discuz.com
DocumentRoot D:/www
ServerName www.xiaojia.com
ServerAlias xiaojia.com xiaojia.net
ErrorLog D:/www/logs/xiaojia.com-error_log
CustomLog D:/www/logs/xiaojia.com-access_log%Y%m%d combined
# Alias /upimg "/home/www/wwwroot/phpchina.cn/upimg/"
# Alias /wiki "/home/www/wwwroot/phpchina.cn/wiki/"
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteCond %{HTTP_HOST} !111cn.net [OR]
# RewriteCond %{HTTP_HOST} !www.111cn.net
# RewriteRule ^(.*)$ http://www.111cn.net$1 [R=301,L]
RewriteRule ^(.*)/archiver/([a-z0-9\-]+\.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3
</IfModule>
</VirtualHost>
$path=$_SERVER["DOCUMENT_ROOT"];//服务器路径
$i = 0;
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$upload_file=$_FILES['pictures']['tmp_name'][$key];//文件被上传后在服务端储存的临时文件名
$imgtype = strtolower(strrchr($_FILES['pictures']['name'][$key],"."));
$name_1 = strtolower(substr($_FILES["pictures"]["name"][$key],0,2));
$upload_file_name= "lanmayi_".time().$name_1.$imgtype;//以字母及系统时间的秒来做文件名
$store_dir = $path."/up_img/";// 上传文件的储存位置
$file_size_max = 100000000000;// 1M限制文件上传最大容量(bytes)
$accept_overwrite = 0;//是否允许覆盖相同文件
move_uploaded_file($upload_file,$store_dir.$upload_file_name);
$new_img_name = $upload_file_name;
$new_img_type = substr($imgtype,1,3);
$new_img_path = $store_dir;
$suo_name = Makesuo ($new_img_path,$new_img_name,$new_img_type);
$sh_time = date('Y-m-d H:i:s');
$name = $_POST['name'];
$pid = $id;
$sql = "insert into lanmayi_img_show(pid,sh_name,sh_url,sh_suo,sh_time) values (".$pid.",'".$name[$i]."','".$upload_file_name."','".$suo_name."','".$sh_time."')";
$res = mysqli_query($conn,$sql);
$i++;
}
}
//*批量上传结束********************************************************
?>
<script language="javascript">
alert("图片上传成功!")
</script>
<?php
}
if($_POST['fanhui']){
?>
<script language="javascript">
window.location='pro_list.php?id=<?php echo $id?>';
</script>
<?php
}
?>
先看htm文件吧
<html>
<head>
<title><{$title}></title>
<{$xajax_javascript}><{*使smarty支持xajax*}>
</head>
<body>
<form name="check" >
请输入用户名:
<input type="text" name="username" />
<input type="button" name="button" value="检查用户名" />
<div id="result"></div>
</form>
</body>
</html>
php处理代码
<?php
/*****************************************
Title :smarty结合xajax检测用户名简单实例
Author:leehui1983(辉老大)
Finish Date :2006-12-09
*****************************************/
//为避免中文乱码,需要在 xajax.inc.php 需要改一下默认的encoding:define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gbk' )UTF8编码格式文件不需要更改
require_once('./libs/Smarty.class.php');//包含smarty类库
require('./xajax/xajax.inc.php');//包含xajax类库
function checkusername($textvalue){//编写需要的PHP函数
$checkresult=($textvalue=='test' ? '<font color=red>该用户名已经注册</font>' :'<font color=red>可以注册</font>');
$objresponse=new xajaxResponse();//实例化xajaxresponse对象
$objresponse->addassign("result","innerHTML",$checkresult);//指定ID为result的元素中添加内容$checkresult
return $objresponse;//返回结果文本
}
$xajax=new xajax();//实例化xajax对象
$smarty=new Smarty();//实例化smarty对象
$smarty->template_dir = "./templates";//设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->caching = false; //设置缓存方式
/*****************************************************
左右边界符,默认为{},但实际应用当中容易与JavaScript
相冲突,所以建议设成<{}>或其它。
*****************************************************/
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$xajax->registerFunction("checkusername");//注册checkusername函数
$xajax->processRequests();//调用xajax用于接管请求
$smarty->assign('xajax_javascript', $xajax->getJavascript('./xajax/'));//输出JS代码,注意('./xajax/')中参数为xajax.inc.php父目录,在同意目录下可不同填写,否则必须填写
$smarty->assign('title','smarty结合xajax检测用户名简单实例');//替换模板内容
$smarty->display('index.tpl');//显示模板内容
?>
相关文章
- 这篇文章主要介绍了源码分析系列之json_encode()如何转化一个对象,对json_encode()感兴趣的同学,可以参考下...2021-04-22
- PHP去除html、css样式、js格式的方法很多,但发现,它们基本都有一个弊端:空格往往清除不了 经过不断的研究,最终找到了一个理想的去除html包括空格css样式、js 的PHP函数。...2013-08-02
- index.php怎么打开?初学者可能不知道如何打开index.php,不会的同学可以参考一下本篇教程 打开编辑:右键->打开方式->经文本方式打开打开运行:首先你要有个支持运行PH...2017-07-06
PHP中func_get_args(),func_get_arg(),func_num_args()的区别
复制代码 代码如下:<?php function jb51(){ print_r(func_get_args()); echo "<br>"; echo func_get_arg(1); echo "<br>"; echo func_num_args(); } jb51("www","j...2013-10-04- 本文介绍基于nodejs+express+art-template的留言板功能。包含列表界面、添加界面和发送留言功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-21
- 这篇文章主要介绍了PHP编程 SSO详细介绍及简单实例的相关资料,这里介绍了三种模式跨子域单点登陆、完全跨单点域登陆、站群共享身份认证,需要的朋友可以参考下...2017-01-25
- 我要实现的就是下图的这种样式,可参考下面这两个网站的留言板,他们的实现原理都是一样的畅言留言板样式:网易跟帖样式:原理 需要在评论表添加两个主要字段 id 和 pid ,其他字段随意添加,比如文章id、回复时间、回复内容、...2015-11-08
- 这篇文章主要介绍了PHP实现创建以太坊钱包转账等功能,对以太坊感兴趣的同学,可以参考下...2021-04-20
- 本文就是和大家分享一款由php结合ajax实现的无刷新留言板,先给大家看一下最后的效果图:数据库连接代码如下: <?php$conn = @mysql_connect("localhost","root","root") or die ("MySql连接错误");mysql_select_db("d...2015-10-30
- 这篇文章主要为大家详细介绍了php微信公众账号开发之五个坑,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-10-02
ThinkPHP使用心得分享-ThinkPHP + Ajax 实现2级联动下拉菜单
首先是数据库的设计。分类表叫cate.我做的是分类数据的二级联动,数据需要的字段有:id,name(中文名),pid(父id). 父id的设置: 若数据没有上一级,则父id为0,若有上级,则父id为上一级的id。数据库有内容后,就可以开始写代码,进...2014-05-31- 这篇文章主要介绍了PHP如何通过date() 函数格式化显示时间,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-13
- 今天我给大家分享的是在不刷新页面的前提下,使用PHP+jQuery+Ajax实现多图片上传的效果。用户只需要点击选择要上传的图片,然后图片自动上传到服务器上并展示在页面上。...2015-03-15
- 这篇文章主要介绍了golang与php实现计算两个经纬度之间距离的方法,结合实例形式对比分析了Go语言与php进行经纬度计算的相关数学运算技巧,需要的朋友可以参考下...2016-07-29
- 这篇文章主要介绍了PHP如何使用cURL实现Get和Post请求,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-07-11
- 这篇文章主要介绍了PHP正则表达式过滤html标签属性的相关内容,实用性非常,感兴趣的朋友参考下吧...2016-05-06
- 经常看到有人踩在了PHP路径的坑上面了,感觉有必要来说说PHP中相对路径的一些坑,以及PHP中绝对路径的使用,下面一起来看看。 ...2016-08-24
- 这篇文章主要为大家详细介绍了php构造方法中析构方法在继承中的表现,感兴趣的小伙伴们可以参考一下...2016-04-15
- 这篇文章主要介绍了thinkPHP中多维数组的遍历方法,以简单实例形式分析了thinkPHP中foreach语句的使用技巧,需要的朋友可以参考下...2016-01-12
- 这篇文章主要介绍了php有序列表或数组中删除指定的值的实现代码,删除给定的值之后,得到一个新的有序列表,长度-1,下面是具体的实现方法...2021-08-22