SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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?

    PHP Code:
    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>';
     } 
    Last edited by cpradio; Mar 1, 2013 at 06:45. Reason: Added [php] tags

  2. #2
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May be you wrong syntax.


    <snip />
    Last edited by cpradio; Mar 1, 2013 at 06:44. Reason: Please wait 90 days for a real signature

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,169
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by robin01 View Post
    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?

    PHP Code:
    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>';
     } 
    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.

    PHP Code:
    $_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:
    PHP Code:
    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>';
     } 

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    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.

    PHP Code:
    $_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:
    PHP Code:
    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

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,169
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by robin01 View Post
    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'].

  6. #6
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,169
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    add a check....

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

  8. #8
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There are two methods to propagate a session id:

    Cookies
    URL parameter
    http://php.net/manual/en/session.idpassing.php

    Use cookies!
    Denny Schlesinger
    web services

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,840
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by captainccs View Post
    In both cases it is only the sessionid string that is passed between pages - the actual session data is all held on the server.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  10. #10
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    ...the actual session data is all held on the server.
    Of course!
    Denny Schlesinger
    web services


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •