-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_note.php
More file actions
31 lines (26 loc) · 733 Bytes
/
save_note.php
File metadata and controls
31 lines (26 loc) · 733 Bytes
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
<?php
// Start session
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: index.html");
exit();
}
// Include database connection file
include_once "db_connection.php";
$userid = $_SESSION['user_id'];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Collect form data
$body = $_POST['note'];
$title = $_POST['title'];
// Insert user data into database
$sql = "INSERT INTO notes (userid, title, body) VALUES ('$userid', '$title', '$body')";
if (mysqli_query($conn, $sql)) {
header("Location: profile.php");
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
// Close connection
mysqli_close($conn);
}
?>