-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsavecomments.php
More file actions
64 lines (42 loc) · 1.2 KB
/
savecomments.php
File metadata and controls
64 lines (42 loc) · 1.2 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
session_start();
include "shared/lock.php";
if($user_type > 2)
{
header("Location: index.php");
}
?>
<?php
mysqli_select_db($conn,DB_DATABASE);
mysqli_query($conn, "set names 'utf8'");
?>
<?php
function text_filter($content)
{
// 将特殊字符转换为 HTML 实体
$content = htmlspecialchars($content);
// 转义元字符集
$content = quotemeta($content);
// 自定义过滤字符串,可以根据业务需求进行扩展
$content = preg_replace('/\'/', "\'", $content);
$content = preg_replace('/\n/', "<br />", $content);
$content = preg_replace('/^\s+/', "", $content);
// . 不进行转换
//$content = preg_replace('/\\\./', ".", $content);
return $content;
}
//用户发来的数据格式:id=所在单元格div的id,即stutid,value就是这个div中新的值
$fileid = $_POST["id"];
$comments = text_filter($_POST["value"]);
//$references = str_replace("\r\n","<br />",$reference);
//撰写一个更新语句
$sql_update_comments = "UPDATE files SET `comments` ='{$comments}' WHERE `id` = '{$fileid}'";
$update = mysqli_query($conn,$sql_update_comments);
if(!$update)
{
echo "保存失败";
}
else{
echo stripcslashes($comments);
}
?>