如何用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>

上一页
本文共 3 页,第  [1]  [2]  [3]  页

Tags:PHP mysql ShoutBox
  • 相关文章

Copyright 2006-2008 Powered by Noheart.NET无心人网络 All Rights Reserved.

QQ:89232083 E-Mail:leijian212@163.com

豫ICP备08004854号