<?php


require_once('include/config.php');
session_start();

if(isset($_GET['act']) && $_GET['act']=='add')
{
if(empty($_POST['username'])){
   echo "<script>window.alert('用户名不能为空！');window.history.back();</script>";
   exit;
}
if(empty($_POST['content'])){
   echo "<script>window.alert('留言内容不能为空！');window.history.back();</script>";
   exit;
}

   $sql = "insert into guestbook(username,img,come,qq,email,homepage,ip,content,posttime) values('".$_POST['username']."','".$_POST['img']."','".$_POST['come'].$_POST['city']."','".$_POST['qq']."','".$_POST['email']."','".$_POST['homepage']."','".$_SERVER['REMOTE_ADDR']."','".nl2br(htmlspecialchars($_POST['content']))."','".date("Y-m-d H:i:s")."')";
   //echo $sql;
   mysql_query($sql) or die("<script>window.alert('没有发表成功，请检查是否包含非法内容！');window.history.back();</script>");
   die("<script>window.alert('留言发表成功！');window.location.href='index.php';</script>");
}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo webname.version ?></title>
<link rel="stylesheet" type="text/css" href="include/main.css" />
</head>

<body>
<?php require_once('head.php');?>
<br>
<table width="600" border="0" cellspacing="0" cellpadding="0" align="center">
<form action="" method="post" name="message">
  <tr>
    <td height="25" colspan="2" align="center"><strong>发表留言</strong></td>
  </tr>
  <tr>
    <td width="132" height="25" align="right">呢称：&nbsp;</td>
    <td width="468" height="25"><label>
      <input name="username" type="text" class="input" id="username" value="" />
    <font color="#ff6600">*</font>（<font color="#ff6600">*</font>为必填项）</label></td>
  </tr>
  <tr>
    <td height="25" align="right">性别：&nbsp;</td>
    <td height="25"><label>
      <input name="img" type="radio" class="redio" value="boy" checked="checked" />
      男
      <input name="img" type="radio" class="redio" value="girl" />
      女</label></td>
  </tr>
  <tr>
    <td height="25" align="right">来自：&nbsp;</td>
    <td height="25"><label>
      <select name="come" class="input" id="come">
        <option>请选择省份</option>
        <option value="北京">北京</option>
        <option value="天津">天津</option>
        <option value="上海">上海</option>
        <option value="重庆">重庆</option>
        <option value="陕西">陕西</option>
        <option value="湖北">湖北</option>
      </select>
      省
      <input name="city" type="text" class="input" id="city" size="10" />
      市/地区
    </label></td>
  </tr>
  <tr>
    <td height="25" align="right">QQ：&nbsp;</td>
    <td height="25"><label>
      <input name="qq" type="text" class="input" id="qq" />
    </label></td>
  </tr>
  <tr>
    <td height="25" align="right">E-mail：&nbsp;</td>
    <td height="25"><label>
      <input name="email" type="text" class="input" id="email" size="30" />
    </label></td>
  </tr>
  <tr>
    <td height="25" align="right">个人主页：&nbsp;</td>
    <td height="25"><label>
      <input name="homepage" type="text" class="input" id="homepage" size="30" />
    </label></td>
  </tr>
  <tr>
    <td height="25" align="right">内容：&nbsp;</td>
    <td height="25"><label>
      <textarea name="content" cols="70" rows="15" class="input" id="content"></textarea>
    <font color="#ff6600">*</font></label></td>
  </tr>
  <tr>
    <td height="25">&nbsp;</td>
    <td height="25"><label>
      <input name="Submit" type="submit" class="botton" value="发表留言" />
      &nbsp;
      <input name="Submit2" type="reset" class="botton" value="重新填写" />
    </label></td>
  </tr></form>
</table>
<br />
<?php 
require_once('foot.php');
?>
</body>
</html>
