473,666 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

$_SESSION array

1 New Member
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) :
Expand|Select|Wrap|Line Numbers
  1.     $qid = $_POST['pstq'];
  2.         $_SESSION[$qid] = array();
  3.  
  4.     foreach ($_SESSION[$qid] as $key=>$value) {
  5.     echo "<table><tr><td> $key : </td><td>$value</td></tr>
  6.     }
  7.  
and i get this notice
Expand|Select|Wrap|Line Numbers
  1. Notice: Unknown: Skipping numeric key 0. in Unknown on line 0
  2.  
of course I start the session etc.
Thnx.
Oct 1 '07 #1
4 9216
djpaul
137 New Member
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) :
Expand|Select|Wrap|Line Numbers
  1.     $qid = $_POST['pstq'];
  2.         $_SESSION[$qid] = array();
  3.  
  4.     foreach ($_SESSION[$qid] as $key=>$value) {
  5.     echo "<table><tr><td> $key : </td><td>$value</td></tr>
  6.     }
  7.  
and i get this notice
Expand|Select|Wrap|Line Numbers
  1. Notice: Unknown: Skipping numeric key 0. in Unknown on line 0
  2.  
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
Oct 1 '07 #2
Atli
5,058 Recognized Expert Expert
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) :
Expand|Select|Wrap|Line Numbers
  1.     $qid = $_POST['pstq'];
  2.         $_SESSION[$qid] = array();
  3.  
  4.     foreach ($_SESSION[$qid] as $key=>$value) {
  5.     echo "<table><tr><td> $key : </td><td>$value</td></tr>
  6.     }
  7.  
and i get this notice
Expand|Select|Wrap|Line Numbers
  1. Notice: Unknown: Skipping numeric key 0. in Unknown on line 0
  2.  
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     session_start();
  3.  
  4.     $qid = "pstg";
  5.     $_SESSION[$qid] = array("one" => 1, 2 => "Two");
  6.  
  7.     echo "<pre>";
  8.     print_r($_SESSION);
  9.     echo "</pre>";
  10. ?>
  11.  
Oct 2 '07 #3
Hemo
1 New Member
Hi, problem is bad key value of Session.
This code causes Notice
Expand|Select|Wrap|Line Numbers
  1. session_start(); 
  2. $_SESSION["1"] = array('hodnota1');
  3.  
This does not cause Notice

Expand|Select|Wrap|Line Numbers
  1. session_start(); 
  2. $_SESSION["1a"] = array('hodnota1');
  3.  
Oct 2 '12 #4
lyodmichael
75 New Member
are you trying to register a session, in a value of a textbox?
Oct 2 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
16275
by: Håvard Olerud Eriksen | last post by:
I've been working on a webshop, and I've got most of the functionality up and running. One problem, however, that I don't seem to be able to solve is as follows. My shopping cart is stored in $_SESSION array. As I need to keep tabs on what items are ordered and their quantity I add elements like this: array_push($_SESSION,array($item => $quantity)); If I add three elements and then var_dump the global variable it spits out: array(3) { =>...
5
10900
by: Rob Tweed | last post by:
Probably a simple question but I can't find the answer anyway. Specifically, is it possible to copy a multidimensional array into the $_SESSION array - ie a deep clone of all keys and data? I naively assumed that $_SESSION = $myArray ; would work but it doesn't appear to work. Is there a single function
0
2478
by: Phil Powell | last post by:
What is the most standardized method of utilizing the CURL functions in PHP (version 4.3.2) to be able to retrieve the contents of a remote URL that happens to be dependent upon $_SESSION for its content display? I've tried the following class methods for display and I have most everything working until I get to a URL that requires $_SESSION: class Timer extends View {
4
3097
by: Tom | last post by:
A small problem that has me kinda baffled. This is the situation: I've set up a self-submitting form FORM.PHP. Once the inputs are validated, the info gets put in SESSION variables and the script redirects the user to a review form REVIEW.PHP which displays the info the user has input and allows them to edit or submit. At the top of that page, I have the following code: --- start code ---
5
1854
by: h | last post by:
I am at my wits end; I can not see A SINGLE THING I'm doing wrong. I've read every fricking session related doc. I've searched every fricking group. NO ONE seems to have had the problem I'm having - and it doesn't make ANY sense. I'm running php 4.3.3 on a local server; and 4.3.10 on my isp's web server. I've tested this on both with the same results.
2
1912
by: Tom | last post by:
I put together a code that checks for 2 post variables then stores them in a multi-dim $_SESSION array, something like this: If ( isset($_POST && isset($_POST) ) { $_SESSION = $_POST; $_SESSION = $_POST; } The problem was that $_SESSION was being overwritten with
12
41161
by: Michael Windsor | last post by:
I've been trying to integrate some PHP pages of my own with some existing code. The details of this are for the support forums for that code (where I have been asking questions), but I wonder if someone here can enlighten me as to why the problematic code is having the effect it is. For reasons I don't know, if the PHP version is 5 or greater, register_long_arrays is false and $_SESSION exists, the following statement is executed: ...
2
1815
by: somecrazyguy | last post by:
Take the following code, one would think that there was absolutely no link between $test and $_SESSION. But if you reload the page, guess what... "After=FAILED". Why? Because for some reason, writing to $test affects the $_SESSION variable $_SESSION. session_start(); ini_set("session.gc_maxlifetime","3600"); if ($_REQUEST == "1") session_unset(); var_dump($_SESSION); if (!$_SESSION) $_SESSION = "Test"; echo...
2
2029
by: gm04030276 | last post by:
hey, i'm basically trying to use php sessions and a bit of javascript to make tabbed browsing within a web page using sessions to store the data of the different opened pages. Problem: when i unset the first 0 index in the array (ie close the default page) it seems to wipe the other one (can't get it to add more that one anymore) from the array also the information is held in sub array $_SESSION each page has its own array of infomation...
2
2263
by: sharonDonnelly | last post by:
Hi Really dumb problem that's got me beat. Can someone help. The prolem: I'm trying to count the number of times an item has been clicked. There are many items. I want to create a session variable for each item as its clicked, and increment the value held by the session variable by 1 each time that item is clicked. My plan was to allow an item to be selected on one page - when a user selects an item, a numeric value will be passed to a...
0
8443
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.