Navin Kumar
Navin Kumar

Reputation: 512

I cannot retrieve session value stored in first php page?

I stored a value of id in first php page as,

<?php

  ...
 $_SESSION["UID"] = $row["JS_ID"];
...

?>

this is the 2nd page,

<?php

  ...
 session_start(); 
$uid=$_SESSION["UID"];
...

?>

when am passing it as value it works,,but when I'm running my project, it's saying error as, "Undefined index UID"..Is there any way to clear it out?

Upvotes: 0

Views: 62

Answers (2)

Joke_Sense10
Joke_Sense10

Reputation: 5402

Try these:

Page1.php:

<?php

...
session_start(); 
$_SESSION["UID"] = $row["JS_ID"];
...

?>

Page2.php:

<?php

...
session_start(); 
$uid=$_SESSION["UID"];
...

?>

Upvotes: 1

GautamD31
GautamD31

Reputation: 28763

First you need to remove the session start from second page and start the session on that first page with

session_start();

Because whenever you have started the session then only you can access the session variables.But You are starting the session on the second page.Which has no use.

Upvotes: 1

Related Questions