-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
106 lines (75 loc) · 3.23 KB
/
contact.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
include 'configs/connect.php';
session_start();
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
} else {
$user_id = null;
};
if (isset($_POST['send'])) {
$name = $_POST['name'];
$name = filter_var($name, FILTER_SANITIZE_STRING);
$email = $_POST['email'];
$email = filter_var($email, FILTER_SANITIZE_STRING);
$number = $_POST['number'];
$number = filter_var($number, FILTER_SANITIZE_STRING);
$msg = $_POST['msg'];
$msg = filter_var($msg, FILTER_SANITIZE_STRING);
// Kiểm tra xem user_id có hợp lệ hay không
if ($user_id !== null) {
$select_message = $conn->prepare("SELECT * FROM `messages` WHERE name = ? AND email = ? AND number = ? AND message = ? AND user_id = ?");
$select_message->execute([$name, $email, $number, $msg, $user_id]);
if ($select_message->rowCount() > 0) {
$message[] = 'Đã gửi tin nhắn rồi !';
} else {
$insert_message = $conn->prepare("INSERT INTO `messages` (user_id, name, email, number, message) VALUES (?, ?, ?, ?, ?)");
$insert_message->execute([$user_id, $name, $email, $number, $msg]);
$message[] = 'Đã gửi tin nhắn thành công !';
}
} else {
// Xử lý khi user_id không hợp lệ
$message[] = 'Không tìm thấy thông tin người dùng! Xin hãy đăng nhập';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" href="templates/uploaded_img/system_img/logo.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>contact</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<!-- custom css file link -->
<link rel="stylesheet" href="templates/css/style.css">
</head>
<body>
<!-- header section starts -->
<?php include 'configs/user_header.php'; ?>
<!-- header section ends -->
<div class="heading">
<h3>Liên hệ</h3>
<p><a href="home.php">Trang chủ</a> <span> / Liên hệ</span></p>
</div>
<!-- contact section starts -->
<section class="contact">
<div class="row">
<div class="image">
<img src="images/contact-img.svg" alt="">
</div>
<form action="" method="post">
<h3>Liên hệ với chúng tôi</h3>
<input type="text" name="name" maxlength="50" class="box" placeholder="Nhập tên" required>
<input type="number" name="number" min="0" max="9999999999" class="box" placeholder="Nhập số điện thoại" required maxlength="10">
<input type="email" name="email" maxlength="50" class="box" placeholder="Nhập email" required>
<textarea name="msg" class="box" required placeholder="Nội dung" maxlength="500" cols="30" rows="10"></textarea>
<input type="submit" value="Gửi" name="send" class="btn">
</form>
</div>
</section>
<?php include 'configs/user_footer.php'; ?>
<script src="templates/js/script.js"></script>
</body>
</html>