Jump to content

How do I add id's to a session?


flit

Recommended Posts

Hi there,

 

I am trying to add id's to a session, but when I click on a link to enter the id into the session,

it overwrites it and does not add an id to the session.

 

I have a page called 6.php with the following lines:

<a href="7.php<? php

session_start();

$_SESSION['id']='1';?>">Test 1</a>

-->writes to the session: id|s:1:"1";

 

<br>

 

<a href="7.php<? php

session_start();

$_SESSION['id']='2';?>">Test 2</a>

-->writes to the session: id|s:1:"2";

 

I want to be able to add an id into the session and not overwrite it.

Can anyone help me?

Link to comment
Share on other sites

Try this:

 

<a href="7.php<? php
session_start();
$_SESSION['id'][] ='1';?>">Test 1[/url]
-->writes to the session: id|s:1:"1";




<a href="7.php<? php
session_start();
$_SESSION['id'][]='2';?>">Test 2[/url]
-->writes to the session: id|s:1:"2";

 

You need to treat it like an array

Link to comment
Share on other sites

When I added some more links, the program writes the id of the last link to the session thus 8

 

<a href="7.php<? php

session_start();

$_SESSION['id']='1';?>">Test 1[/url]

 

<a href="7.php<? php

session_start();

$_SESSION['id']='2';?>">Test 2[/url]

 

<a href="7.php<? php

session_start();

$_SESSION['id']='3';?>">Test 3[/url]

 

<a href="7.php<? php

session_start();

$_SESSION['id']='8';?>">Test 8[/url]

 

Help?

Link to comment
Share on other sites

When I press the first link I want to write 1 to the session file but when I press 1 it writes 8 to the session file

 

When I press the second link I want to write 2 to the session file but when I press 2 it writes 8 to the session file

 

When I press the third link I want to write 3 to the session file but when I press 3 it writes 8 to the session file

 

I want my session file to look like this:

1,2,3,8.......

 

I used to do this with <a href="99.php?action=add&id=1">Add id 1 to session</a>

but I don't want to use that technique. I don't want the action=add&id=1 message printed

in my web browser. I want to add id's like the links below.

 

<a href="7.php<? php

session_start();

$_SESSION['id']='1';?>">Test 1[/url]

 

<a href="7.php<? php

session_start();

$_SESSION['id']='2';?>">Test 2[/url]

 

<a href="7.php<? php

session_start();

$_SESSION['id']='3';?>">Test 3[/url]

 

<a href="7.php<? php

session_start();

$_SESSION['id']='8';?>">Test 8[/url]

 

All I want to do is insert a id value into a session by clicking on a link, and retrieve the id's later to print some mysql info on a page

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.