-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_mood.php
More file actions
54 lines (42 loc) · 1.5 KB
/
submit_mood.php
File metadata and controls
54 lines (42 loc) · 1.5 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
<?php
session_start(); // Start the session to access user_id
// Database configuration
$servername = "sql111.infinityfree.com"; // Change if needed
$username = "if0_39103916"; // Change if needed
$password = 'Mu5abM51'; // Change if needed
$dbname = "if0_39103916_zenlog";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
die("User not logged in.");
}
$user_id = $_SESSION['user_id'];
// Get form data
$mood_level = $_POST['mood_level'];
$mood_comments = $_POST['mood_comments'];
$mood_triggers = $_POST['mood_triggers'];
// Validate and sanitize input
$mood_level = $conn->real_escape_string($mood_level);
$mood_comments = $conn->real_escape_string($mood_comments);
$mood_triggers = $conn->real_escape_string($mood_triggers);
// Prepare and execute SQL query
$sql = "INSERT INTO mood_data (user_id, mood_level, mood_comments, mood_triggers) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
if (!$stmt) {
echo "Prepare failed: " . $conn->error;
exit;
}
$stmt->bind_param("iiss", $user_id, $mood_level, $mood_comments, $mood_triggers);
if ($stmt->execute()) {
echo "Mood reflection submitted successfully! Relod the page to update your Mood-Chart :)";
} else {
echo "Execute failed: " . $stmt->error;
}
$stmt->close();
$conn->close();
?>