Home php教程 php手册 用PHP构建一个留言本

用PHP构建一个留言本

Jun 21, 2016 am 09:14 AM
address echo php quot varchar

下面是配置说明:

  为了配置的方便,重新整理了代码,现在已经把全部的需要设置的参数都放在config.php文件里了,配置起来应该很简单,里面有详悉的说明.
  目标:在十分种内搞定你的留言本!!!

  1: 建立一个数据库(要主页提供数据库空间)

  一般的有phpMyAdmin开放源玛的前端.创建以来很简单的. 取好名字后,记得把config.php 的$db_name改成这个名字

  2: 建立留言数据表表(等下把config.php的$table_name改成这里你起的名字).

  结构为:

key_liuyan int(11) auto_increment primary key, //主建,自动增加
nikename varchar(20) null // 昵称
subject varchar(100) null // 留言主题
date_created varchar(19) // 留言时间
ip_address varchar(15) // 留言人的IP地址
message mediumtext null // 留言信息
email_address varchar(50) null // 留言人的e-mail地址
zhuye_address varchar(50) null // 留言人的主页地址
huifu_biaozi int(1) default 0 // 版主回复标志
huifu mediumtext null // 版主回复内容
oicq varchar(20) null // 留言人的OICQ号码

  可以用如下的SQL来完成!!!(本人测试通过,记得把yourtable_name改成好记点的, 当然不改也行阿)

create table your_liuyan_table(
 key_liuyan int(11) auto_increment primary key,
 nikename varchar(20) null,
 subject varchar(100) null,
 date_created varchar(19) ,
 ip_address varchar(15),
 message mediumtext null,
 email_address varchar(50) null,
 zhuye_address varchar(50) null,
 huifu_biaozi int(1) default 0 ,
 huifu mediumtext null,
 oicq varchar(20) null
)

  3: 建立控制表:(同样要把这里起的名字放到config.php的$table_name_control里去)

  结构如下:

leibie varchar(20) primary key,
value varchar(20) null

  也可以用下面的SQL语句:

create table your_control_table(

 leibie varchar(20) primary key,
 value varchar(20) null
)

  因为这是你的控制表,所以要自己加入控制记录两条;

  SQL语句为:

  插入删除密码:

insert into your_control_tble( leibie, value)
 values (delete,'1332');

  插入回复密码:

insert into your_control_tble( leibie, value)
values (huifu,'1332');

  这样放进去的密码为:123,用户名为空!

  怎么计算密码和插入的值的关系呢?

  是这样的,你的密码 ,如123 把三位数上的各位加起来,等于6,然后把6乘以222就是密码值!!!

6*222=1332.

  知道了这关系,当然你可以改成其它的密码了.

  不过用户名要为空,,,

  4: 一切完成,然后只要把除了readme.txt外的文件上传就行了.

post.php 文件
<?php
require('config.php');
?>

<?php

$nikename=$arr_request['nikename'];

if (strlen($nikename)==0)
{
echo "<center>";

echo "<h2><font color=red>错误信息!</font></h2>";
echo "对不起,<font color=red>呢称</font>必须填写!!! 请重填!<br>";
echo "<hr></hr>";
echo "免费留言本由<a href=http://little.oso.com.cn>小熊</a>提供技术支持";
echo "</center>";
exit ;

}

$date_now=date('Y/m/d H:i:s');
$ip_address=getenv("REMOTE_ADDR");
$messageold=$arr_request['message'];
//$pattern="/n/";
//$replacement="<br>";

$message=computer_message($messageold,$hang_zifu_number);

$subjectold=$arr_request['subject'];
if (strlen($subjectold)>$hang_zifu_number)

$subject=computer_message($subjectold,$hang_zifu_number);
else
$subject=$subjectold;

$str_sql=" insert into $table_name
(nikename,subject,date_created,ip_address,message,email_address,zhuye_address,oicq)
values
( '$nikename',
'$subject',
'$date_now',
'$ip_address',
'$message',
'".$arr_request['email_address']."',
'".$arr_request['zhuye_address']."',
'".$arr_request['oicq']."'

)";

$result=mysql_db_query($db_name,$str_sql,$id_link);

if (! $result){
affy_error_exit('SQL Insert Execution has failed.');
}

else

{

echo "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">";
echo "<HTML><HEAD><TITLE>发表文章</TITLE>";
echo "<META content="text/html; charset=gb2312" http-equiv=Content-Type>";
echo "<meta HTTP-EQUIV="REFRESH" CONTENT="2;URL=display.php">";
echo "</head><body topmargin="0"><br>";
echo "<ul>谢谢你发表留言,将自动显示留言内容";
echo " <br>";
echo "<a href=display.php>如果你的浏览器没有自动的返回到留言簿首页,?
请点这里返回.";
echo "</a></ul>";

exit;

}
?>

index.html 文件

<html>
<center>

<title>谢谢你的留言!</title>
<h1><font color=blue>我的留言本</font></h1>
<font color=navy>首先感谢你的留言,你的每一句话我都会仔细阅读!!!</font>

<form action="post.php" method="post">
<table>
<tr>
<td><font color=teal>呢称:</font><font color=red>(不能为空)</font></td><td>
<input type="text" name="nikename" value=""></td>
</tr>

<tr>
<td>OICQ号码:</td><td>

<input type="text" name="oicq" value=""></td>
</tr>
<tr>
<td>e-mail: </td><td>
<input type="text" name="email_address" value="" size="30"></td>
</tr>
<tr>
<td>个人主页:</td><td>
<input type="text" name="zhuye_address" value="http://" size="40"></td>
</tr>
<tr><td>
主题:</td><td>
<input type="text" name="subject" size="40" ></td>
</tr>
<tr><td>
内容:</td><td> </td>
</tr>
<tr><td colspan="2">
<textarea name="message" cols="60" rows="8"></textarea></td>
</tr>
<tr>
<td>
<input type="submit" value="完成留言">
</td>
<td>
<input type="reset" value="重新来过">
</td>
</tr>
</table>
</form>
<p>
<a href=display.php>查看留言</a>
<hr></hr>
免费留言本由<a href="http://little.oso.com.cn" >小熊</a>提供技术支持

</center>

</html>

display.inc文件!!!


<tr bgcolor=>
<td>
<a href=mailto:<?php echo $record->email_address ?> >
<font color="blue" size=4><strong><?php echo $record->nikename ?></strong></font>
</a>
</td>
<td><font color="navy">留言时间:<?php echo $record->date_created ?></font></td>

<td>来自:

<?php
$ip_address=ip_question($record->ip_address);
echo $ip_address;
?>

</td>
</tr>
<tr bgcolor=>
<th colspan=3 align=left>主题:<font color=teal><?php echo $record->subject ?></font></th>

</tr>

<tr><th colspan=3 align=left><font color="#416AAF">
<?php echo $record->message ?></font></th>
</tr>


<?php

if ($record->huifu_biaozi)
{
?>
<tr><th colspan=3 align=left><font color="red"><br><br>版主回复:</font><font color="navy">
<?php echo $record->huifu ?></font></th>
</tr>
<?php

}

?>

<tr>
<th colspan=3 align=left><br>
<a href=mailto:<?php echo $record->email_address ?> >
<img src=http://www.163design.net/p/b/image/mail.gif
alt="<?php echo $record->nikename ?>的e-mail地址是:<?php echo $record->email_address ?> "
border="0" width="15" length="15">邮件</a>
<a href=<?php echo $record->zhuye_address ?>><img src=http://www.163design.net/p/b/image/home.gif
alt="<?php echo $record->nikename ?>的主页地址是:<?php echo $record->zhuye_address ?> "
border="0"
width="14" length="14" >主页</a>
<img src=http://www.163design.net/p/b/image/oicq.gif border="0" alt="<?php echo $record->nikename?>的OICQ是:
<?php echo $record->oicq ?>"
width="14" length="14" >OICQ</a>

<a href=action.php?action=delete&key_liuyan=<?php echo $record->key_liuyan ?>><img src=http://www.163design.net/p/b/image/del.gif border="0" width="12" length="12" alt="只有版主才有删除的权限哦!">删除</a>
<a href=action.php?action=huifu&key_liuyan=<?php echo $record->key_liuyan ?> ><img src=http://www.163design.net/p/b/image/replay.gif border="0" width="14" length="14" alt="不好意思,现在暂时只有版主才能回复">回复</a>

</th></tr>

<tr>
<td colspan="3"><hr SIZE ="1"></td>
</tr>



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles