Reputation: 2060
I am trying to echo my session but it isn't showing. I think the session is working because this is the same code as every other page. The only part that displays is the text..."Your id is" and "League Home". Can someone please help me figure out what is wrong with my code?
<?php
// this starts the session
session_start();
$id = $_SESSION['userid'];
echo "Your id is " . $id;
//this connects to the database
$con = mysql_connect("localhost","yourfan3_jeengle","armyjoe30");
mysql_select_db("yourfan3_demo", $con);
//gets info for user
$result = mysql_query("SELECT * FROM League_Info WHERE User_ID = '$id'");
$result2 = mysql_fetch_array($result);
$leaguename = $result2['League'];
echo $leaguename;
//$result31 = $result2['Members'];
//$result32 = $result2['League_Password'];
//checks if league name exists
$memberslist = mysql_query("SELECT User_ID FROM League_Info WHERE League = '$leaguename'");
?>
<html>
<head>
</head>
<body>
League Home
</body>
</html>
Upvotes: 0
Views: 73
Reputation: 5104
You did not define $_SESSION['userid']
as anything, therefore there is nothing for it to echo. Make sure you give it a value then proceed with the echo.
Upvotes: 0
Reputation: 33512
You don't seem to set $_SESSION['userid'];
in the code at all. Are you sure that there is an ID set when this is being run?
run this echo $_SESSION['userid'];
and see if it returns anything?
Upvotes: 0
Reputation: 14310
The session is a special array that you can use to store data. If you did not set $_SESSION['userid'] somewhere else in your code, you will not be able to call it back here.
Upvotes: 1