<?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>";