<?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 */
/* 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" onMouseOver="window.status='Add your name';return true" onMouseOut="window.status='';return true" 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");
/* 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);
/* 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" onMouseOver="window.status='请您留言';return true" onMouseOut="window.status='';return true" TITLE="Add your name to our guestbook">请您留言</A></FONT></H4>";