-
Notifications
You must be signed in to change notification settings - Fork 4
/
faq.php
77 lines (54 loc) · 1.83 KB
/
faq.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
<?php
session_start();
// //SET THE HOST
// $host = 'localhost';
// $database = 'ecycle1';
// $username = 'root';
// $pwd = '';
// // ESTABLISH AND CHECK CONNECTION
// $connection = mysqli_connect( $host, $username, $pwd, $database);
// if($connection){
// }else{
// die("ERROR: Could not connect. " . mysqli_connect_error());
// }
// $fname="";
// $email="";
// $message="";
// //creating a connection to the server
$connection =mysqli_connect('localhost', 'root', '', 'ecycle1');
//checking if connection is succesful
if(!$connection){
die("could not connect to server" . mysqli_connect_error());
}
if(isset($_POST['send'])) {
$fname = $_SESSION['fname'];
$message = $_SESSION['message'];
$email = $_SESSION['email'];
// checking empty fields
if(empty($fname) || empty($message) || empty($email)) {
if(empty($fname)) {
echo "<font color='red'>Name field is empty.</font><br/>";
}
if(empty($message)) {
echo "<font color='red'>Message field is empty.</font><br/>";
}
if(empty($email)) {
echo "<font color='red'>Email field is empty.</font><br/>";
}
//link to the previous page
echo "<br/><a href='javascript:self.history.back();'>Go Back</a>";
} else {
// if all the fields are filled (not empty)
//insert data to database
$insert_query="INSERT INTO contacts(fname,message,email) VALUES('$fname','$message','$email')";
mysqli_query($connection,$insert_query);
//display success message
echo "<font color='green'>Data added successfully.";
session_destroy();
header('location: home.html');
}
}else{
header('location: home.html');
}
//mysqli_close($connection);
?>