如何用PHP和mysql创建一个ShoutBox
- 作者:williamlong 来源:月光博客 文章点击数:
最后, 我们需要一个 PHP 文件处理表单.
-- 文件#4: newshout.php --
<?
# Simply Shouting - a shoutbox example
# File name: newshout.php
# Description: Process the HTML form on index.php and redirect.
//得到留言者姓名
$shoutby = $_POST['shoutby'];
if($shoutby == "Enter your name here"||$shoutby == ""){
//如果没有输入名字
$shoutby = "Visitor";
}
if($_POST['shout']){
// 留言信息
if($_POST['shout'] != "Click & Shout!"){
//they didn't shout the default, so continue processing
$shout = $_POST['shout'];
//替换掉"<"和">"以阻止黑客
$shout = str_replace("<", " ", $shout);
$shout = str_replace(">", " ", $shout);
// 包含数据信息
include_once("dbaccess.php");
// 连接数据库
$connection = @mysql_connect($host, $user, $password) or die(mysql_error());
$db = @mysql_select_db($name,$connection) or die(mysql_error());
// 插入留言信息到数据库
$sql = "INSERT INTO `shouts`(`shoutby`,`shout`) VALUES('$shoutby','$shout')";
//关闭连接
$result = @mysql_query($sql,$connection);
}
}
?>
<html>
<head>
</head>
<body onLoad="window.open('index.php','_self')">
</body>
</html>
- 相关文章
| ·关于PHP在linux下面获取GOOGLE的PR值 | 07-15 |
| ·PHP程序不适用大型系统的九大原因 | 07-15 |
| ·Mysql使用Describe命令判断字段是否存在 | 07-12 |
| ·MySQL UPDATE时主键冲突引发的思考 | 07-12 |
| ·使用PHP模拟HTTP认证 | 07-10 |
| ·分享是Wodig开源的精髓 | 07-10 |
| ·从IIS的ASP迁移到APACHE的PHP的方法 | 07-07 |
| ·ASP、PHP和JSP的比较 | 07-02 |
