-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedback.php
More file actions
82 lines (73 loc) · 2.66 KB
/
Copy pathfeedback.php
File metadata and controls
82 lines (73 loc) · 2.66 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// Database connection details
$servername = "localhost";
$username = "root";
$password = "1234";
$database = "login_register";
// Create connection
$conn = new mysqli($servername, $username, $password, $database, 3307);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Prepare SQL statement to insert feedback into database
$stmt = $conn->prepare("INSERT INTO feedback (name, email, feedback, rating) VALUES (?, ?, ?, ?)");
$stmt->bind_param("sssi", $name, $email, $feedback, $rating);
// Get form data
$name = $_POST['name'];
$email = $_POST['email'];
$feedback = $_POST['feedback'];
$rating = $_POST['rating'];
// // Execute SQL statement
// if ($stmt->execute()) {
// echo "Feedback submitted successfully!";
// } else {
// echo "Error: " . $stmt->error;
// }
// Check if email exists in database
$stmt = $conn->prepare("SELECT * FROM feedback WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
// if ($result->num_rows > 0) {
// // Email exists, update feedback
// $stmt = $conn->prepare("UPDATE feedback SET name = ?, feedback = ?, rating = ? WHERE email = ?");
// $stmt->bind_param("ssis", $name, $feedback, $rating, $email);
// if ($stmt->execute()) {
// echo "Feedback updated successfully!";
// } else {
// echo "Error: " . $stmt->error;
// }
// } else {
// // Email does not exist, insert feedback
// $stmt = $conn->prepare("INSERT INTO feedback (name, email, feedback, rating) VALUES (?, ?, ?, ?)");
// $stmt->bind_param("sssi", $name, $email, $feedback, $rating);
// if ($stmt->execute()) {
// echo "Feedback submitted successfully!";
// } else {
// echo "Error: " . $stmt->error;
// }
// }
if ($result->num_rows > 0) {
// Email exists, update name and other feedback details
$stmt = $conn->prepare("UPDATE feedback SET name = ?, feedback = ?, rating = ? WHERE email = ?");
$stmt->bind_param("ssis", $name, $feedback, $rating, $email);
if ($stmt->execute()) {
echo "Feedback updated successfully!";
} else {
echo "Error: " . $stmt->error;
}
} else {
// Email does not exist, insert new feedback
$stmt = $conn->prepare("INSERT INTO feedback (name, email, feedback, rating) VALUES (?, ?, ?, ?)");
$stmt->bind_param("sssi", $name, $email, $feedback, $rating);
if ($stmt->execute()) {
echo "Feedback submitted successfully!";
} else {
echo "Error: " . $stmt->error;
}
}
// Close statement and connection
$stmt->close();
$conn->close();
?>