-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.php
More file actions
63 lines (57 loc) · 1.99 KB
/
comment.php
File metadata and controls
63 lines (57 loc) · 1.99 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
<?php
session_start();
require_once('config.php');
error_reporting(0);
@$myidea = addslashes($_POST['myidea']);
$myidea = trim($myidea);
$myidea = htmlspecialchars($myidea); #防XSS
@$author = addslashes($_POST['author']);
$author = trim($author);
$author = htmlspecialchars($author);
$time = date("Y-m-d");
$time = (string)$time;
$time = trim($time);
$conn = new mysqli($GLOBALS['db_addr'],$GLOBALS['db_user'],$GLOBALS['db_pass'],$GLOBALS['db_name']);
$sql = "INSERT INTO comment(author,comment,subtime) values ('{$author}','{$myidea}','{$time}')";
if (isset($myidea) && strlen($myidea) > 0 && isset($author) && strlen($author) > 0){
//$conn = new mysqli($GLOBALS['db_addr'],$GLOBALS['db_user'],$GLOBALS['db_pass'],$GLOBALS['db_name']);
$result = $conn->query($sql);
if (!$result === TRUE){
echo "Error comment".'<br>'.$conn->error;
}
}
?>
<?php require_once('header.php');?>
<form class="ui reply form" method="POST">
<div class="field">
<label>Author</label>
<input type="text" name="author" placeholder="Your name">
</div>
<div class="field">
<label>Content</label>
<textarea name="myidea" placeholder="输入您的留言..."></textarea>
</div>
<button class="ui button" type="submit">留言</button>
</form>
</div>
<div class="ui comments">
<h3 class="ui dividing header">留言板</h3>
</div>
<?php
$conn = new mysqli($GLOBALS['db_addr'],$GLOBALS['db_user'],$GLOBALS['db_pass'],$GLOBALS['db_name']);
$sql_1 = "SELECT `author`,`comment`,`subtime` FROM comment";
$query = $conn->query($sql_1);
echo '<div class="ui comments">';
if ($query->num_rows > 0){
while($row = $query->fetch_array()){
echo '<div class="comment"><a class="avatar"><img src="/emmmm/images/comment.jpg"></a><div class="content">';
echo '<a class="author">'.$row['author'].'</a>';
echo '<div class="metadata"><span class="date">'.$row['subtime'].'</span></div>';
echo '</div></div><div class="text">'.$row['comment'].'</div>';
}
}
$conn->close();
?>
</div>
</body>
</html>