How do you make the cookies in getdata.php retrieve data from the results of index.php?
// index.php
<?php
require_once('db/connection.php');
// Fetch data from the database
$stmt = $conn->prepare("SELECT * FROM user WHERE username = :username");
$stmt->bindParam(':username', $_GET['username']);
$stmt->execute();
// Fetch data as an associative array
$result = $stmt->fetch();
// Check if data exists
if(!$result) {
header("Location: /monki/login");
exit; // Terminate script after redirect
}
?>
// getdata.php
<?php
require_once('../db/connection.php');
// Fetch data from the database
$stmt = $conn->query("SELECT post.*, user.*
FROM post
INNER JOIN user ON post.user_id = user.user_id
WHERE post.user_id = '$_COOKIE[user_id]'");
$stmt->bindParam(':user_id', $user_id);
$posts = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Return the data as JSON
header('Content-Type: application/json');
echo json_encode($posts);
?>
Creating get url in angularjs from database