-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
45 lines (44 loc) · 1.52 KB
/
post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/*该文件用于发布信息*/
require_once "Database.class.php";
require_once "status.class.php";
//少了提交参数不予插入
if(isset($_REQUEST['topic_id'])&&isset($_REQUEST['content'])&&isset($_REQUEST['author'])&&isset($_REQUEST['sendTime'])&&isset($_REQUEST['incognito']))
{ //接受参数
$topic_id=$_REQUEST['topic_id'];//话题id
$content=$_REQUEST['content'];//帖子内容
$author=$_REQUEST['author'];//作者
$sendTime=$_REQUEST['sendTime'];//发送时间
$incognito=$_REQUEST['incognito'];//是否匿名
$conn=mysql_connect($_SERVER['SERVER_NAME'],Database::$database_username,Database::$database_userpassword);
mysql_select_db(Database::$selectdatabase);
mysql_query("set names utf8");
$sql="insert into ".Database::$database_topic_table." (topic_id,sendTime,author,incognito,comments,content) values ('".$topic_id."','".$sendTime."','".$author."','".$incognito."','0','".$content."')";//初始评论数为0
$res=mysql_query($sql);
if(!$res)//插入错误情况
{
$s=array('status'=>Status::$status[3]);
$show['status']=$s['status'];
$show['response']=array(null);
echo json_encode($show);
exit();
}
if(mysql_affected_rows()>0)
{
$s=array('status'=>Status::$status[0]);
$show['status']=$s['status'];
$show['response']=array(null);
echo json_encode($show);
exit();
}
}
else
{
//少了参数立即输出203错误
$s=array('status'=>Status::$status[3]);
$show['status']=$s['status'];
$show['response']=array(null);
echo json_encode($show);
exit();
}
?>