-
Notifications
You must be signed in to change notification settings - Fork 0
/
dealnews.php
51 lines (51 loc) · 1.52 KB
/
dealnews.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
46
47
48
49
50
51
<?php
session_start();
require_once "mysqlTool.php";
isset($_REQUEST['action']) or die("no action");
$action=strtolower($_REQUEST['action']);
switch($action){
case "add":{
($_SESSION['status']=="yes") or die("非法登录");
isset($_REQUEST['title']) or die("no title");
isset($_REQUEST['content']) or die("no content");
$title=$_REQUEST['title'];
$content=$_REQUEST['content'];
$sql="insert into news (title,content) values('$title','$content')";
mysql_query($sql) or die(mysql_error());
};break;
case "delete":{
($_SESSION['status']=="yes") or die("非法登录");
isset($_REQUEST['id']) or die("no id");
$id=$_REQUEST['id'];
$sql="delete from news where id='$id'";
mysql_query($sql) or die(mysql_error());
};break;
case "getnewslist":{
$sql="select * from news order by id desc";
$return=array();
$res=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_assoc($res)){
unset($row['content']);
$return[count($return)]=$row;
}
echo json_encode($return);exit;
};break;
case "getnewscontent":{
isset($_REQUEST['id']) or die("no id");
$id=$_REQUEST['id'];
$sql="select * from news where id='$id'";
$res=mysql_query($sql) or die(mysql_error());
$row=array();
if($row=mysql_fetch_assoc($res)){
echo json_encode($row);
mysql_query("update news set click_amount=click_amount+1 where id='$id'");
exit;
}
echo json_encode($row);exit;
};break;
default:die('无效指令');break;
}
echo '<script>
history.go(-1);
</script>';
?>