BBS(php amp;amp;amp; mysql)完整版(一)

方法已於方法,其中的地方也上得的,我只是把它消化吸收后重新写了更全面的出来。公布出只是希望更多的新手能中到一些西。如果你代有任何意可以留言,但勿行人身攻,我是一菜只能出的西,每个老鸟都有这样的过程。

1.guestbook.php html head script language=JavaScript !– !– var
hellotext=为了您的最佳浏览效果请您使用IE4.0以上的版本和800*600分辨率
var thetext= var started=false var step=0 var times=1 function
welcometext() { times– if (times==0) { if (started==false) { started =
true; window.status = hellotext; setTimeout(anim(),1); } thetext =
hellotext; } } function showstatustext(txt) { thetext = txt;
setTimeout(welcometext(),4000) times++ } function anim() { step++ if
(step==7) {step=1} if (step==1) {window.status=’===’+thetext+’===’} if
(step==2) {window.status=’===’+thetext+’===’} if (step==3)
{window.status=’==’+thetext+’==’} if (step==4)
{window.status=’==’+thetext+’==’} if (step==5)
{window.status=’===’+thetext+’===’} if (step==6)
{window.status=’===’+thetext+’===’} setTimeout(anim(),200); } // —
welcometext(); function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+.location=’+selObj.options[selObj.selectedIndex].value+’);
if (restore) selObj.selectedIndex=0; } //– /script
title天地网络留言版/title meta content=text/html; charset=gb2312 /head
style type=text/css !– a:link {font-size: 9pt; color: #FFFFFF} —
/style body ? $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 目前没有留言!a
href=guestbook.htm欢迎您留言!/a;} if($rownum == ) { $rownum = 1; }
$AA=CEIL($rownum/5); $i=0 ; echo TABLE WIDTH=100%tddiv font size=2
color=#000000B共有留言:$rowcount 条共:$PAGES 页right现在是第 $AA
页/right/B/font/div/td; echo hr size=1 color=#ccccffwidth=75%; while
($myrow=mysql_fetch_array($result)){ $i++;
if(($i=$rownum)&&($i$rownum+5)){ echo table width=75% border=1
cellspacing=0 cellpadding=0 bordercolordark=#FFFFFF
bordercolorlight=#000000 background=15.JPG; echo trtd width=15%div font
size=2 color=#FFFFFF姓 名/font/div/tdtd width=85%font size=2
color=#FFFFFF$myrow[username]/font/td/tr; echo trtd width=15%div font
size=2 color=#FFFFFF电子信箱/font/div/tdtd width=85%font size=2
color=#FFFFFFa href=mailto:$myrow[email]$myrow[email]/font/a/td/tr;
echo trtd width=15%div font size=2 color=#FFFFFF公司主页/font/div/tdtd
width=85%font size=2 color=#FFFFFFa href=$myrow[homepage]
target=_blank$myrow[homepage]/font/a/td/tr; echo trtd width=15%div
font size=2 color=#FFFFFF留言主题/font/div/tdtd width=85%font size=2
color=#FFFFFF$myrow[topic]/font/td/tr; echo trtd width=15%div font
size=2 color=#FFFFFF留言内容/font/div/tdtd width=85%font size=2
color=#FFFFFF$myrow[content]/font/td/tr; echo trtd width=15%div font
size=2 color=#FFFFFF留言时间/font/div/tdtd width=85%font size=2
color=#澳门新葡亰平台游戏网站,FFFFFF$myrow[date]/font/td/tr; echo /tablehr size=1
color=#ccccffwidth=75%;} } echo table width=100%trtd width=87%;
#判断是否有或 echo form name=hiddenform method=post
action=guestbook.php; echo div input type=hidden name=rownum value=;
echo input type=hidden name=rowcount value=$rowcount; #显示 if
($rownum=5) echo input type=submit value=
onclick=document.hiddenform.rownum.value=.($rownum-5).; #显示 if
($rownum+5=$rowcount) { echo input type=submit value=
onclick=document.hiddenform.rownum.value=.($rownum+5)./div; } echo
/form; echo /td; echo /tr; echo /table; echo table width=100% trtddiv
font color=#ffffff size=2a
href=guestbook.htm返回继续发言/a/font/div/td/tr/table; ? /body /html
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 请填写必要的项目或着非法用户名!a
href=javascript:history.go(-1);返回/a; } //wrong email ? elseif
(($email!=)and(!eregi(^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$,$email)))
{ echo 请您填写正确的 E-Mail 地址/pp a
href=javascript:history.go(-1);返回/a; } //wrong homepage ? elseif
(($homepage!=)and(!eregi(()+[0-9a-z-]+.([0-9a-z-]+.)+[a-z]{2,3}$,$homepage)))
{echo 主页地址输入错误!a href=javascript:history.go(-1);返回/a;} 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对不起!请先a
href=register.html注册/a!; } 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 div
font size=2 color=#000000谢谢您留言!您的留言已成功加入,a
href=guestbook.php返回/a/font/div; } } ? 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 ‘已有人注册此名,请重新选择名字!a
href=javascript:history.go(-1);返回/a’;} else {$query=insert into
tb(username,password) values(‘$username’,’$password’);
mysql_query($query); echo ‘注册成功’; echo ‘A HREF=guestbook.htm
请登录!/A’;} ? 以下是两个配套的HTML: 1。留言网页 html head meta
content=text/html; charset=gb2312 meta name=GENERATOR content=Microsoft
FrontPage 4.0 meta name=ProgId content=FrontPage.Editor.Document
title天地网络留言版欢迎您留言!/title /head body bgcolor=#FFFFFF div
align=center center br font size=2天地网络留言版测试版/fontbr br form
method=post action=show.php3 table width=66% tr td width=50% height=1
div align=center font size=2 您的尊姓大名:/font/div /td td width=50%
height=1 div align=center input type=text name=name size=20 /div /td /tr
tr td width=50% height=1 div align=centerfont size=2
您的电子邮件地址:/font/div /td td width=50% height=1 div align=center
input type=text name=email size=20 /div /td /tr tr td width=50% height=1
div align=centerfont size=2 您的公司主页地址:/font/div /td td width=50%
height=1 div align=center input type=text name=homepage size=20 value=
/div /td /tr tr td width=50% height=1 div align=center font
size=2留言主题:/font/div /td td width=50% height=1 valign=middle div
align=center input type=text name=topic size=20 /div /td /tr tr td
width=50% height=1 div align=center font size=2留言内容:/font/div /td
td width=50% height=1 div align=center /div /td /tr tr td width=100%
colspan=2 height=66 p align=center textarea rows=10 name=content
cols=50/textarea /p /td /tr tr td width=50% height=18 div
align=center/div /td td width=50% height=18 div align=center/div /td /tr
tr td width=50% height=18 align=center p align=center input type=submit
value=发表留言 name=B1 /p /td td width=50% height=18 align=center div
align=center input type=reset value=全部重写 name=B2 /div /td /tr /table
/form /center /div p /p p /p /body /html 2.注册程序 html head
titleregiste/title meta content=text/html; charset=gb2312 /head body
bgcolor=#FFFFFF div align=center p/p p/p p用户注册/p form method=post
action=zhuc.php p用户名: input type=text name=username /p p密码: input
type=password name=password /p p input type=submit name=Submit
value=确定 input type=reset name=Submit2 value=重来 /p /form p/p /div
/body /html 如需要ZIP文件可给我来信。tandinet@163.net

//此页面为say.php ? include signup/mysql.inc; if($id1){ $sql=select *
from $table where id=’$id1′;//显示回复题目 $result=mysql_query($sql)or
die(mysql_error()); $row=mysql_fetch_array($result);
$title=RE:.$row[title]; } $ip=$REMOTE_ADDR; $sql=select * from
user_stus where ip=’$ip’;//查询当前用户名 $result=mysql_query($sql)or
die(mysql_error()); $row=mysql_fetch_array($result);
if(!$row)//判断用户是否登陆 { echo htmldiv id=Layer2 z-index:1BRBRBRBR;
echo div id=Layer3 z-index:2img src=pic/3.gif width=15 height=15/div;
echodiv ;echo pfont size=2 color=#FF33CC嘻嘻!! 请先登陆/font/p;
echopfont size=2 color=#FF33CCa
href=’.$PHP_SELF.?p=1&&table=$table’返回/a/font/p /div /html; exit(); }
else $userid=$row[userid]; if($ok) { if($title==||$content==) { echo
BR请您添完整后提交; } else{ $id=time();//提交文章 $date1=date(Y/m/d);
$title=htmlspecialchars($title); $content=htmlspecialchars($content);
$sql=select * from .$table; $result=mysql_query($sql)or
die(mysql_error()); $row1=mysql_num_rows($result); $row1++; if($id1){
$sql=insert into bbs_re
(id,userid,date1,title,content)values(‘$id’,’$userid’,’$date1′,’$title’,’$content’);
mysql_query($sql)or die(mysql_error()); $sql=select * from .$table.
where id=’$id1′; $result=mysql_query($sql)or die(mysql_error());
$lin=mysql_fetch_array($result); for($i=1;$i6;$i++) { $re=r.$i;
if(!$lin[$re]) break; } $sql=update .$table. set .$re.=’$id’ where
id=’$id1′; } else$sql=insert into .$table.
(id,userid,date1,title,content,row)values(‘$id’,’$userid’,’$date1′,’$title’,’$content’,’$row1′);
$result=mysql_query($sql)or die(mysql_error()); if($result) {
header(Location:php3.php?p=1&&table=$table); exit ; } } } ? html head
titlexiaoyang/title meta content=text/html; charset=gb2312 script
language=JavaScript1.2 src=js/menu_comment.js/script script
language=JavaScript1.2 src=js/fw_menu.js/script script
language=JavaScript !– function MM_reloadPage(init) {//reloads the
window if Nav4 resized if (init==true) with (navigator) {if
((appName==Netscape)&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW ||
innerHeight!=document.MM_pgH) location.reload(); }
MM_reloadPage(true); // — /script /head body bgcolor=#FFFFFF
text=#000000 div id=Layer1 style=position:absolute; left:31px; top:1px;
width:560px; height:46px; z-index:10 script
language=JavaScript1.2fwLoadMenus();/script/div div id=Layer6
style=position:absolute; left:409px; top:29px; width:118px; height:17px;
z-index:6/div div id=Layer5 style=position:absolute; left:86px;
top:63px; width:464px; height:303px; z-index:7form name=form1
method=post action=? echo $PHP_SELF ? table width=98% border=1
cellspacing=0 cellpadding=0 bordercolor=#FF99FF trtd width=26%
height=42div align=centerfont size=2 color=#FF33FF题目/font/div /td td
width=74% height=42input type=text name=title size=40 value=?echo $title
;? onMouseover=this.document.form1.title.focus();return true input
type=hidden name=table value=?echo $table ;? input type=hidden name=id1
value=? echo $id1 ;? br /td /tr trtd width=26% height=172div
align=centerfont size=2 color=#FF33FF内容/font/div /td td width=74%
height=172textarea name=content cols=40 rows=10 wrap=physical
value=?echo $content ;?
onMouseOver=this.document.form1.content.focus()/textarea /td /tr tr td
width=26% div align=center input type=reset name=Submit2 value=重写 /div
/td td width=74% div align=center input type=submit name=ok value=发表
/div /td /tr /table p/p /form /div div id=back style=position:absolute;
left:455px; top:30px; width:85px; height:3px; z-index:8hr color=#ff9999
noshade /div div id=goback style=position:absolute; left:461px;
top:23px; width:120px; height:16px; z-index:9div align=centera
href=php3.php?p=1&&table=?echo $table ;? target=_self
onMouseover=window.status=” ;return truefont size=2
color=#FF33FF返回/font/a/div /div p/p p/p /body /html

鉴于时间问题,代的提交部分使用的是传统的表单POST,如果您喜欢可以根据LOAD过程自行加上相应的SCRIPT,不过好像只
能用GET了。XML可以真正的刷新,如果手上有希望能借看看。

在此感QQ群中蓝雪狐和shelly水在JS上予的助,也新手能把自己的功能代出大家一起研究。

最後附上演示地址:_input.php
喜HACK他人器的朋友手下留情,附上演示是了朋友能更快了解代。

input.php[HTML] 接受用户输入数据。

PHP代码:———————————————-

?php /* 申 明 ——————————
该演示文件详细描述了利用JS+PHP对数据库进行似刷新读出写入的方法
2004年02月14日 By L.Fox */

header(“Cache-Control: no-store, no-cache,must-revalidate”);
//行可以取消,把文件存成HTML echo $_POST[“name1”];
//我是了?#123;方便才加的。 ? html head meta “Content-Type”
content=”text/html; charset=??????”
title根据编号从MYSQL提取数据进行编辑并回存[演示]/title script
language=”JavaScript” /script style body { font-family: “Verdana”,
“Arial”, “Helvetica”, “sans-serif”; font-size: 12px; line-height: 17px;
scrollbar-base-color: #BBBBBB; scrollbar-shadow-color: #BBBBBB;
scrollbar-highlight-color: #FFFFFF; scrollbar-3dlight-color: #000000;
scrollbar-darkshadow-color: #000000; scrollbar-arrow-color: #FFFFFF; }
table { border: 0; font-size: 12px; cursor: default; } td { text-align:
left; height: 20; } input { width: 100; height: 18; border: 0px solid
#666666; text-align: left; } /style script var objInput = null; var
objTd = null; var num =null; function AutoEdit(obj,id) { if (objInput ==
null) { objTd = obj; obj.innerHTML = “input size=”10″ maxlength=”10″
type=”text” value=”” + obj.innerText + “”
onblur=”objTd.innerText=this.value;LoadData(objTd.innerText,num);objInput=null;”
“; objInput = document.getElementById(“objInput”); objInput.focus(); } }

function LoadData(LoadIndex,LoadObj) { var
LoadFileName=”load.php?action=” + LoadIndex + “num=” + LoadObj;
document.getElementById(“LoadDataSrc”).src = LoadFileName; } function
OutPutData(obj) { if (form1.num1.value.length1){ alert(“请输入数量1”);
return false;} if (form1.num2.value.length1){ alert(“请输入数量2”);
return false;} if (document.getElementById(“name1”).innerHTML.length1){
alert(“name1空值”); return false;} if
(document.getElementById(“name2”).innerHTML.length1){
alert(“name2空值”); return false;} obj.innerHTML=”input type=”hidden”
name=”name1″ value=”” + document.getElementById(“name1”).innerHTML +
“””; obj.innerHTML+=”input type=”hidden” name=”name2″ value=”” +
document.getElementById(“name2”).innerHTML + “””; obj.innerHTML+=”input
type=”hidden” name=”type1″ value=”” +
document.getElementById(“type1”).innerHTML + “””; obj.innerHTML+=”input
type=”hidden” name=”type2″ value=”” +
document.getElementById(“type2”).innerHTML + “””; obj.innerHTML+=”input
type=”hidden” name=”date1″ value=”” +
document.getElementById(“date1”).innerHTML + “””; obj.innerHTML+=”input
type=”hidden” name=”date2″ value=”” +
document.getElementById(“date2”).innerHTML + “””;
obj.innerHTML+=form1.submit(); } function postdata() { form1.submit(); }
/script /head body form name=”form1″ method=”post”
action=”load.php?action=OutPutData” table width=”400″ cellpadding=”0″
cellspacing=”1″ align=”center” bgcolor=”#999999″ tr bgcolor=”#EFEFEF”
td onclick=”AutoEdit(this,num=1)” div/div/td td
onclick=”AutoEdit(this,num=2)” div/div/td /tr tr bgcolor=”#EFEFEF”
tddiv a/div/td tddiv b/div/td /tr tr bgcolor=”#EFEFEF” tddiv a/div/td
tddiv b/div/td /tr tr bgcolor=”#EFEFEF” tddiv /div/td tddiv /div/td /tr
tr bgcolor=”#EFEFEF” tddivinput type=”text” name=”num1″ value=””/div/td
tddivinput type=”text” name=”num2″ value=””/div/td /tr div a href=”#”

onclick=”java script:OutPutData(this);”输出/a/div/form /body /html

LOAD.php

PHP代码:———————————————–

?php header(“Cache-Control: no-store, no-cache,must-revalidate”);
include(“obj/financial_obj_free.inc”);
//这个文件里的内容是连接MYSQL的语句。 $str=$_GET[“action”];
$num=$_GET[“num”]; if ($str==”OutPutData”) OutPutData(); else {
linkdata(“financial”,1); $sql=”select * from table where id=$str”; if
($query=mysql_query($sql)) { $temdata=mysql_fetch_row($query);
//看看是不是空的,如果是就附上值以免JS报错。 if
(strlen($temdata[2])1||$temdata[2]==””) $temdata[2]=”空”;
$temdata[2]=htmlspecialchars($temdata[2]); if
(strlen($temdata[3])1||$temdata[3]==””) $temdata[3]=”空”;
$temdata[3]=htmlspecialchars($temdata[3]); if
(strlen($temdata[5])1||$temdata[5]==””) $temdata[5]=”空”;
$temdata[5]=htmlspecialchars($temdata[5]); } else {
$temdata[2]=$temdata[3]=$temdata[5]=”查询失败”; } switch ($num)
//这个主要是用于检查是从第几列(行)传过来的。注意变量值要与input的id值对应好.否则出错
{ case 1: $diva=”name1″; $divb=”type1″; $divc=”date1″; break; case 2:
$diva=”name2″; $divb=”type2″; $divc=”date2″; break; default:
$diva=”name1″; $divb=”type1″; $divc=”date1″; break; }
//确定节点,输出$temdata[X]到节点$divX; echo
“document.getElementById(“.$diva.”).innerHTML=”.$temdata[2].”;”; echo
“document.getElementById(“.$divb.”).innerHTML=”.$temdata[3].”;”; echo
“document.getElementById(“.$divc.”).innerHTML=”.$temdata[5].”;”; }

function OutPutData() //这下面如果改成SQL语句就可以写进数据库 { echo
“输出的数据如下,改成SQL语句然后就可以保存下来”; echo
“编号1=”.$_POST[“name1″].”br”; echo “编号2=”.$_POST[“name2″].”br”;
echo “名称1=”.$_POST[“type1″].”br”; echo
“名称2=”.$_POST[“type2″].”br”; echo “日期1=”.$_POST[“date1″].”br”;
echo “日期2=”.$_POST[“date2″].”br”; echo
“数量1=”.$_POST[“num1″].”br”; echo “数量2=”.$_POST[“num2″].”br”;
echo “a href=”text_input.php”返回/a”; } ?

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图