<?php 
session_start();
$bt="新的日记";
include("../head.php");
include("../conn.php");
include_once("../function.php");
$sid = sqlstr($_COOKIE['dl']);
$uin=mysql_fetch_array(mysql_query("select * from user where sid='$sid'"));
$id=$uin['id'];
$tel=$uin["phone"];
/*
if($tel==Null){
header("Location:index.php");
exit;//没登录就跳转到登录页面
}
*/
if(!$uin){
header("Location:../login.php");
exit;//没登录就跳转到登录页面
}
$time=time();//用于记录时间
$text=htmlspecialchars($_POST["diarytxt"]);
$zz=sqlstr($_POST["diaryzz"]);
if($zz!=2){
$zz=1;
}
$txt=sqlstr(nl2br($text));
if($txt==Null){
echo '<br/><font color="red">很无语啊：</font><br/>你什么都不写，你想表达什么呢？写一点吧。<br/><a href="add.php">返回新的日记</a><br/><br/>';
}elseif(mb_strlen($txt,'utf-8')>2000){
echo "新日记字数不能大于2000哦，一线印象装不下啦~ <br/><a href='add.php'>返回新的日记</a><br/><br/>";
}else{
$ok=mysql_fetch_array(mysql_query("select * from diary where diarytxt='$txt' AND diarywriteid='$id'"));
if($ok){
echo "<br/><br/><font color='red'>你已经写下了一模一样的日记了，回去看看？</font><br/> <br/><a href='index.php'>返回首页</a><br/><br/> ";
}else{

mysql_query("INSERT INTO diary(diarytxt,diaryzz,diarywriteid,diarytime) VALUES ('$txt', '$zz','$id','$time')");
header("Location:index.php");
exit;//发布成功跳转到日记页面
}
}

?>

<?php include("../footer.php"); ?>