0

I've set my session data and it seems to be set as var_dump($_SESSION["favfilms"]["title"]) suggests returning me a massive string with all the correct session data. However when I go to output the data by specifying echo $_SESSION["favfilms"]["title"] I get an error for an Undefined index?

Here's the code for setting the session variables

<?php
ob_start();
session_start();
$category = $_POST["category"];

$_SESSION["fav$category"]["title"] = $_POST["title"];
$_SESSION["fav$category"]["body"] = $_POST["body"];
$_SESSION["fav$category"]["img"] = $_POST["img"];
$_SESSION["fav$category"]["category"] = $_POST["category"];
$_SESSION["fav$category"]["id"] = $_POST["id"];   

?>

Here is the code where I go to render the data to the view

var_dump($_SESSION);
//prints all the session data in one long array structured string
if(isset($_SESSION["favfilms"])){
  echo $_SESSION["favfilms"]["title"] ."<br>";
  echo $_SESSION["favfilms"]["body"]."<br>";
  echo $_SESSION["favfilms"]["img"]."<br>";
  echo $_SESSION["favfilms"]["category"]."<br>";
}else{
  echo "Session fav not set";
  echo $_SESSION["favfilms"]["title"];
}

How do I go accessing my session data?

Here is the String it returns me with all my session data

array(3) { 
        ["username"]=> string(4) "mfal" 
        ["password"]=> string(3) "pwd" 
        ["favfilms "] => array(5) { 
                    ["title"]=> string(10) "Epic Film!" 
                    ["body"]=> string(449) "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat merpproident, merpproidentmerpproident merpproident mollit anim id est laborum." 
                    ["img"]=> string(49) "http://localhost:4000/reviews.com/img/entebbe.jpg" 
                    ["category"]=> string(6) "films " 
                    ["id"]=> string(1) "3" 
                    } 
        } 

Session fav not set

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
unkwndev
  • 99
  • 1
  • 8

0 Answers0