专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » phpwind:PHP »正文

phpwind:PHP

来源: 发布时间:星期日, 2008年10月26日 浏览:238次 评论:0
.2 留言簿程序(guestbook.PHP3):
<?PHP
/* $host : your MySQL-host, usually 'localhost' */
/* $user : your MySQL-username */
/* $password : your MySQL-password */
/* $database : your MySQL-database */
/* $table : your MySQL-table */
/* $page_title : the title of your guestbook-pages */
/* $admin_mail : email-address of the administrator to send the new entries to */
/* $admin_name : the name of the administrator */
/* $html_mail : say yes if your mail-agent can handle HTML-mail, else say no */
$host = "localhost";
$user = "";
$password = "";
$database = "mydb";
$table = "guestbook";
$page_title = "pert guestbook";
$admin_mail = "[email protected]";
$admin_name = "Webmaster";
$html_mail = "no";
?>
<HTML>
<HEAD>
<TITLE><?PHP echo $page_title; ?></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000000">
<FONT FACE="Verdana" SIZE="-2">
<?
/* connect to the database */
MySQL_pconnect("$host","$user","$password") or die("Can't connect to the SQL-server");
MySQL_select_db("$database");
/* action=view : retrieve data from the database and show it to the user */
if($action == "view") {
/* function for showing the data */
function search_it($name) {
/* some vars */
global $offset,$total,$lpp,$dir;
global $table,$html_mail,$admin_name,$admin_mail;
/* select the data to get out of the database */
$query = "SELECT name, email, job, comments FROM $table";
$result = MySQL_query($query);
$total= MySQL_numrows($result);
print "<CENTER><FONT FACE="Verdana" SIZE="-2"><A HREF="guestbook.PHP3?action=add" TITLE="Add your name">加入留言</A></FONT></CENTER><br><br>";
if ($total== 0) {
print "<CENTER>此刻没人留言</CENTER><br><br>"; }
elseif ($total> 0) {
/* default */
$counter=0;
if ($dir=="") $dir="Next";
$lpp=5;
if ($offset==0) $offset=0;
if ($dir=="Next") {
if ($total > $lpp) {
$counter=$offset;
$offset+=$lpp;
$num=$offset;
if ($num > $total) {
$num=$total; } }
else {
$num=$total; } }
elseif ($dir=="Previous") {
if ($total > $lpp) {
$offset-=$lpp;
if ($offset < 0) {
$offset=0; }
$counter=$offset-$lpp;
if ($counter < 0)
$counter=0;
$num=$counter+$lpp; }
else {
$num=$total; } }
while ($counter < $num) {
$j=0;
$j=$counter + 1;
/* now really grab the data */
$i1=MySQL_result($result,$counter,"name");
$i2=MySQL_result($result,$counter,"email");
$i3=MySQL_result($result,$counter,"job");
$i4=MySQL_result($result,$counter,"comments");
$i4 = stripslashes ("$i4");
/* print it in a nice layout */
print "<CENTER>n";
print "<TABLE WIDTH=400 BORDER=0 ALIGN=CENTER VALIGN=TOP><TR><TD><FONT FACE="Verdana" SIZE="-2">n";
print "<HR>n";
print "<BR><B>Name:</B> $i1n";
print "<BR><B>email:</B><A HREF="mailto:$i2" TITLE="Email $i2">$i2</A>n";
print "<BR><B>Job:</B> $i3n";
print "<BR><B>Comment:</B>n";
print "<BR>$i4n";
print "</FONT></TD></TR></TABLE>n";
print "</CENTER>n";
$counter++;
}
}
MySQL_close();
}
/* execute the function */
search_it($name);
/* See if we need to put on the NEXT or PREVIOUS buttons */
if ($total > $lpp) {
echo("<form action="$PHP_SCRIPT" method="POST">n");
/* See if we need a PREVIOUS button */
if ($offset > $lpp) {
echo("<input type="submit" value="Previous" name=dir>n"); }
/* See if we need a NEXT button */
if ($offset < $total) {
echo("<input type="submit" value="Next" name=dir>n"); }
echo("<input type=hidden name="offset" value="$offset">n");
echo("<input type=hidden name="name" value="$name">n");
echo("</form>");
}
}
/* action=add : show a form where the user can enter data to add to the database */
elseif($action == "add") { ?>
<TABLE WIDTH="460" ALIGN="CENTER" VALIGN="TOP">
<TH COLSPAN="2"><P>请您填写留言</TH>
<FORM NAME="guestbook" ACTION="guestbook.PHP3?action=send" METHOD="POST">
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">
您的大名:</TD>
<TD><INPUT TYPE=text NAME=name></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">
您的E-mail:</TD>
<TD>
<INPUT TYPE=text NAME=email></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">
您的工作:</TD>
<TD>
<INPUT TYPE=text NAME=job></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">
您的留言:</TD>
<TD>
<TEXTAREA NAME=comments COLS=40 ROWS=6></TEXTAREA>
<P>
<INPUT TYPE=submit VALUE=Submit> <INPUT TYPE=Reset VALUE=Reset>
<A ALIGN="RIGHT" HREF="guestbook.PHP3?action=view" TITLE="Read all comments first"><FONT SIZE="-2">先观看所有的留言</FONT></A>
</TD>
</TR>
</FORM>
</TABLE>
</CENTER>
<?
}
/* action=send : add the data from the user into the database */
elseif($action == "send") {
/* check if a HTML-mail should be send or a plain/text mail */
if($html_mail == "yes") {
mail("$admin_name <$admin_mail>","PHP3 Guestbook Addition","<HTML><BODY><FONT FACE="Century Gothic"><TABLE BORDER="0" WIDTH="100%" CELLSPACING="4"><TR>$name ($email) schreef het volgende bericht in het gastenboek :</TR><TR><TD ALIGN="LEFT"> </TD><TD ALIGN="LEFT" NOWRAP> </TD></TR><TR><TD ALIGN="LEFT">$comments</TD><TD ALIGN="LEFT" NOWRAP> </TD></TR><TR><TD ALIGN="LEFT"> </TD><TD ALIGN="LEFT" NOWRAP> </TD></TR><TR><TD ALIGN="LEFT">您的留言:</TD><TD ALIGN="LEFT" NOWRAP>$name</TD></TR><TR><TD ALIGN="LEFT">您的大名:</TD><TD ALIGN="LEFT" NOWRAP>$email</TD></TR><TR><TD ALIGN="LEFT">您的email:</TD><TD ALIGN="LEFT" NOWRAP>$job</TD></TR><TR><TD ALIGN="LEFT">您的工作:</TD></TR></TABLE></BODY></FONT></HTML>", "From: $name <$email>nReply-To: $name <$email>nContent-type: text/htmlnX-Mailer: PHP/" . PHPversion());
}

/* MySQL really hates it when you try to put things with ' or " characters into a database, so strip these...*/
$comments = addslashes ("$comments");
$query = "INSERT INTO guestbook VALUES('','$name', '$email', '$job', '$comments')";
$result = MySQL_QUERY($query);
?>
<BR><P ALIGN = CENTER>感谢, <?PHP echo $name; ?>, 您的留言.
<BR><P ALIGN = CENTER><A HREF="guestbook.PHP3?action=view" TITLE="View your comment now">观看留言</A><BR><BR>
<?
}
/* if there's no action given, then we must show the main page */
else {
/* get the number of entries written into the guestbook*/
$query = "SELECT name from guestbook";
$result = MySQL_QUERY($query);
$number = MySQL_NUMROWS($result);
if ($number == "") {
$entry = "还没有人留过言"; }
elseif ($number == "1") {
$entry = "目前留言人数1人"; }
else {
$entry = "目前留言人数 $number 人"; }
echo "<CENTER><BR>";
echo "<P>$entry<BR>";
echo "<H4><FONT FACE="Verdana" SIZE="3"><A HREF="guestbook.PHP3?action=add" TITLE="Add your name to our guestbook">请您留言</A></FONT></H4>";
if ($number > "") {
e
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: