problem with sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paul_20k
Forum Commoner
Posts: 45
Joined: Fri Nov 10, 2006 7:02 pm

problem with sessions

Post by paul_20k »

Hi

I have 15 links on a page. There are different types of mysql queries on all those linked pages. I am getting the variable for these queries from another page by passing that variable through URL.

When I open the first page , it works fine and I am using session to pass that variable value to the rest of the linked pages. I can reach variable on all those pages. But as soon as I leave the first page, I can't open that page again. I am getting that variable on the first page by $_GET and passing values to other pages by sessions.

I can open all other pages as many times as I want but I can't open the first page again. Am I making some mistake with the GET and SESSIONS? I am using this session on first page. I am using this name variable on all other pages.

Code: Select all

session_start();
$_SESSION['name']=$_GET['name'];
I am getting error message after I try to open the first page.

Code: Select all

Notice: Undefined index: name in c:\program files\.................php on line 5
I tried all options but nothing worked so far.

Thanks
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

use

Code: Select all

isset($_GET['name'])
This should solve the problem


Dude
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Alternative approach would be

Code: Select all

if(isset($_GET['name'])){
    $name = $_GET['name'];
}
if(!empty($name)){
    $_SESSION['name'] = $name;
}
paul_20k
Forum Commoner
Posts: 45
Joined: Fri Nov 10, 2006 7:02 pm

Post by paul_20k »

hi

thanks for replies. its working now.
Post Reply