-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
210 lines (189 loc) · 7.44 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
session_start();
$cookie_name = 'name';
if(isset($_COOKIE[$cookie_name])) {
$name = $_COOKIE[$cookie_name];
}
if(isset($_COOKIE['role'])) {
$role = $_COOKIE['role'];
}
$servername = "localhost";
$username = "root";
$password = "test";
$db_name = "myDB";
$errName = "";
$errEmail = "";
$errMessage = "";
$success = false;
if (isset($_POST["submit"]))
{
$fname = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Check if name has been entered
if (!$_POST['name']) {
$errName = '* Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = '* Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = '* Please enter your message';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
// Create connection
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else{
$sql = "INSERT INTO myDB.Feedback (username, email, message) VALUES ('$fname', '$email', '$message');";
if ($conn->query($sql) === TRUE) {
$_POST = array();
$success = true;
}
/*else {
echo "Unable to submit feedback: " . $conn->error;
} */
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Contact</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/contact.css">
<style type="text/css">
a{
color: #EEEDEB;
}
.text-danger{
color: #EEEDEB;
}
</style>
</head>
<body style="background-color: #990000; color: #EEEDEB">
<nav>
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<a class="navbar-brand" href="home.php">HoosierBazaar</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="about.php">About Us</a> </li>
<li><a href="contact.php">Contact Us<span class="sr-only">(current)</span></a> </li>
<?php
if(isset($name))
{
?>
<li><a href="viewBookmarks.php">My Bookmarks</a></li>
<?php
if(isset($role) && (strcmp($role, 'Admin') == 0) )
{ ?>
<li><a href="feedback.php">View Feedback</a></li>
<?php
}
}
?>
</ul>
<ul class="nav navbar-nav navbar-right hidden-sm">
<?php
if(isset($name))
{
?>
<li><a href="login_page/logout.php?redirect_url=<?php echo $_SERVER['PHP_SELF']; ?>">Logout</a></li>
<li><a href="#">Welcome <?php echo $name; ?>!</a></li>
<?php
}
else {
?>
<li><a href="login_page/login.html">Login / Register</a></li>
<?php
}
?>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1 class="page-header text-center">Stop by and say Hi! We love Feedback!</h1>
<form class="form-horizontal" role="form" method="post" action="contact.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="Full Name" value="<?php
if( isset($_POST['name']) )
echo htmlspecialchars($_POST['name']);
?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="[email protected]" value="<?php
if( isset($_POST['email']) )
echo htmlspecialchars($_POST['email']);
?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php
if( isset($_POST['message']) )
echo htmlspecialchars($_POST['message']);
?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div style="clear: both;"></div>
<!--
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
</div>
</div -->
</form>
</div>
</div>
<br>
<footer class="text-center my-footer">
<div class="container">
<div class="row">
<div class="col-xs-12">
<p>Copyright © HoosierBazaar.com All rights reserved.</p>
</div>
</div>
</div>
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-1.11.3.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="application/javascript">
<?php
if($success){
echo "alert('Feedback submitted')";
}
?>
</script>
</div>
</body>
</html>