$_SESSION array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mistrig
    New Member
    • Oct 2007
    • 1

    $_SESSION array

    Hi, I'm trying to create a session array and give a dynamic name.

    I tried something like this but I get only the last entry i made (key=0) :
    [code=php]
    $qid = $_POST['pstq'];
    $_SESSION[$qid] = array();

    foreach ($_SESSION[$qid] as $key=>$value) {
    echo "<table><tr><td > $key : </td><td>$value</td></tr>
    }
    [/code]
    and i get this notice
    Code:
    Notice: Unknown: Skipping numeric key 0. in Unknown on line 0
    of course I start the session etc.
    Thnx.
    Last edited by Atli; Oct 1 '07, 01:32 AM. Reason: Added [code] tags.
  • djpaul
    New Member
    • Oct 2006
    • 137

    #2
    Originally posted by mistrig
    Hi, I'm trying to create a session array and give a dynamic name.

    I tried something like this but I get only the last entry i made (key=0) :
    [code=php]
    $qid = $_POST['pstq'];
    $_SESSION[$qid] = array();

    foreach ($_SESSION[$qid] as $key=>$value) {
    echo "<table><tr><td > $key : </td><td>$value</td></tr>
    }
    [/code]
    and i get this notice
    Code:
    Notice: Unknown: Skipping numeric key 0. in Unknown on line 0
    of course I start the session etc.
    Thnx.
    But then different:
    [PHP]
    $qid = $_POST['pstq'];

    $_SESSION['qid'] = $qid
    [/PHP]

    Because the super global is already some kind of array.
    I used it to for my site and added some vaibles as email, status and so on.
    Good luck!

    Paul

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Originally posted by mistrig
      Hi, I'm trying to create a session array and give a dynamic name.

      I tried something like this but I get only the last entry i made (key=0) :
      [code=php]
      $qid = $_POST['pstq'];
      $_SESSION[$qid] = array();

      foreach ($_SESSION[$qid] as $key=>$value) {
      echo "<table><tr><td > $key : </td><td>$value</td></tr>
      }
      [/code]
      and i get this notice
      Code:
      Notice: Unknown: Skipping numeric key 0. in Unknown on line 0
      of course I start the session etc.
      Thnx.
      Hi. Welcome to The Scripts!

      The obvious error there is the missing quote-mark and semi-colon at the end of the echo statement. But, assuming that is a typo I would point out that your new $_SESSION[$qid] array is initialized each time you run the scripts as an empty array, which would presumably cause the foreach loop to be skipped entirely.

      I can see no reason for the notice, however.

      I did try something similar myself, which executed without warnings and gave me the results I expected:
      [code=php]
      <?php
      session_start() ;

      $qid = "pstg";
      $_SESSION[$qid] = array("one" => 1, 2 => "Two");

      echo "<pre>";
      print_r($_SESSI ON);
      echo "</pre>";
      ?>
      [/code]

      Comment

      • Hemo
        New Member
        • Oct 2012
        • 1

        #4
        Hi, problem is bad key value of Session.
        This code causes Notice
        Code:
        session_start(); 
        $_SESSION["1"] = array('hodnota1');
        This does not cause Notice

        Code:
        session_start(); 
        $_SESSION["1a"] = array('hodnota1');

        Comment

        • lyodmichael
          New Member
          • Jul 2012
          • 75

          #5
          are you trying to register a session, in a value of a textbox?

          Comment

          Working...