-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
78 lines (69 loc) · 2.54 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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once ("connection_pdo.php");
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
try {
// Prepare the SQL statement
$query = "INSERT INTO contact (name, email, subject, message) VALUES (?, ?, ?, ?)";
$stmt = $connection_pdo->prepare($query);
// Bind parameters
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $email);
$stmt->bindParam(3, $subject);
$stmt->bindParam(4, $message);
// Execute the statement
$stmt->execute();
// Check if the insertion was successful
if ($stmt->rowCount() > 0) {
echo "<div class='message'>
<p>Message sent successfully ✨</p>
</div><br>";
} else {
echo "<div class='message'>
<p>Message sending failed 😔</p>
</div><br>";
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
<link rel="stylesheet" href="css/style1.css">
</head>
<body>
<div class="container">
<div class="form-box box">
<form action="#" method="POST">
<div class="input-container">
<input class="input-field" type="text" placeholder="Name" name="name" required>
</div>
<div class="input-container">
<input class="input-field" type="email" placeholder="Email Address" name="email" required>
</div>
<div class="input-container">
<input class="input-field" type="text" placeholder="Subject" name="subject" required>
</div>
<div class="input-container">
<textarea class="input-field" placeholder="Message" name="message" required></textarea>
</div>
<div class="input-container">
<input type="submit" name="submit" value="Send Message" class="btn">
</div>
</form>
<a href="index.php"><button class="btn">Go Back</button></a>
</div>
</div>
</body>
</html>