Passing session variable through herf

Hello,

Im trying to pass a session variable through a link but my approach seems to add unnecessary information into the session variable and i’m looking for alternative to my approaches to passing the variable. I highlighted the problem area below.

Currently everything after the equal sign is added to the session variable, $_SESSION[‘taskid’] = $row[‘ci_taskid’][/B] . " ’ > " . $row[‘ci_taskid’]

how do i just sign $_SESSION[‘taskid’] = $row[‘ci_taskid’] when a user click on the link?

while($row = mysqli_fetch_assoc($ProjectListResults)) 
{	echo '<tr>'; 
	echo "<td> <a href='projectassessment.php?taskid=" . $_SESSION['taskid'] = $row['ci_taskid']  . " ' > " . $row['ci_taskid'] . "</a></td>";
	echo '<td>' . $row['ci_firstname'] . ' '.$row['ci_lastname']. '</td>';
	echo '<td>' . $row['ci_projectid']. '</td>';
	echo '<td>'  . $row['ci_sde'] . '</td>';
	echo '<td>' . $row['ci_status']. '</td>';
	echo '<td>' . $row['ci_title']. '</td>';
	echo '</tr>';
 }

May be you wrong syntax.

<snip />

First, yes, your syntax is wrong. Second, your understanding of SESSION is flawed.

So let’s start with the flawed understanding of SESSION. The purpose of session is to store information about a specific user across the time they spend on your website. You DO NOT need to pass anything via a URL, this information is handled by PHP automatically. You simply have to write to session and read from it.

$_SESSION['taskid'] = 1; // write to session
$taskid = $_SESSION['taskid']; // read from session

Okay, so now that you know that, because you are in a while loop, using SESSION is pointless. Instead you want to pass a value via the URL to another page. You don’t need SESSION for that.

What your code should be doing:

while($row = mysqli_fetch_assoc($ProjectListResults)) 
{	echo '<tr>'; 
	echo "<td><a href='projectassessment.php?taskid=" . $row['ci_taskid']  . "'> " . $row['ci_taskid'] . "</a></td>";
	echo '<td>' . $row['ci_firstname'] . ' '.$row['ci_lastname']. '</td>';
	echo '<td>' . $row['ci_projectid']. '</td>';
	echo '<td>' . $row['ci_sde'] . '</td>';
	echo '<td>' . $row['ci_status']. '</td>';
	echo '<td>' . $row['ci_title']. '</td>';
	echo '</tr>';
 }

Hello cpradio,

Thanks for your help and its my fault for not posting more information about the request and i apologize for that.

Originally I did have the script passing the variable like you stated in your post and it works. problem: The receiving page is a basic data entry page which could be used for multiple entries but for some reason after completing the first entry the variable that i sent over is lost. So, i was hoping that if i passed the variable through a session variable that i would have access to it all the time.

I know my problem area :
echo “<td> <a href='projectassessment.php?taskid=” . $_SESSION[‘taskid’] = $row[‘ci_taskid’] . " ’ > " . $row[‘ci_taskid’] . “</a></td>”;

Dont know how to fix this.

Im open to alternative options.

basically, I want to pass a variable to the next page a data entry page which i need to reuse over and over again.

Thanks for your help

On projectassessment.php, assign $_SESSION[‘taskid’] so it receive the value of $_GET[‘taskid’]. Then any page visited after projectassessment.php will be able to read it from session using $_SESSION[‘taskid’].

Its been tried before.

projectassessment.php has the following line of code:
$_SESSION[‘taskid’] = $_GET[‘taskid’];

problem, when the page performance the save and then returns back to the projectassessment.php the session variable is empty. since the session variable is set by $_get the $_get is empty when it returns back to projectassessment.php as no value is set. the url line is empty of taskId value as well and in turn the session variable is empty.

add a check…

if (isset($_GET['taskid'])) $_SESSION['taskid'] = $_GET['taskid'];

There are two methods to propagate a session id:

Cookies
URL parameter

http://php.net/manual/en/session.idpassing.php

Use cookies!

In both cases it is only the sessionid string that is passed between pages - the actual session data is all held on the server.

Of course!