473,789 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

accessing values from an array

i having trouble accessing the values from superglobal arrays. there
are two situations but i'm pretty sure it's the same problem.

here's the deal:

on page1.php i have several check boxes. before listing them i have
the code
$info = array();

and then each checkbox has

<input type="checkbox" name="info[]" value="Red">Red <br>
<input type="checkbox" name="info[]" value="Blue">Bl ue<br> ...and so
on

the form posts to the same page, then checks the info and cleans it up
if needed. then it sets it to a session variable like so:

if (isset($_POST['submitted'])){

$errors = array();

if(!empty($_POS T['info'])){
$_SESSION['info'] = escape_data($_P OST['info']);} else {
$errors = 'bad';}
}

then it directs you to the next page, page2.php.

on page2.php, i can't figure out how to access the array. i want to
print each element of the array on a seperate line. w/o all the other
it would look something like:

echo "$info[1]<br>";
echo "$info[2]<br>";

i'd like to do this with a foreach loop but i can't even access one
variable. not sure where to go from here.

NOTE: when i was doing it earlier and passing the information from page
to page with the post method and then finally sending myself an email
with all the array infromation imploded into a string, it worked fine.

thanks for your time and knowledge.
-michael

Nov 22 '05 #1
3 1563
>on page2.php, i can't figure out how to access the array. i want to
print each element of the array on a seperate line. w/o all the other
it would look something like:

echo "$info[1]<br>";
echo "$info[2]<br>";


Shouldn't it be:

echo $_SESSION['info'][0] . "<br/>";
echo $_SESSION['info'][1] . "<br/>";

Or, if you want a foreach loop:

foreach($_SESSI ON['info'] as $val)
echo $val . " was checked<br/>";

Nov 22 '05 #2
thanks, but i've tried that:
echo $_SESSION['info'][0] . "<br/>";
echo $_SESSION['info'][1] . "<br/>";


it seems that though $_SESSION['info'] is a set it only contains the
word "Array". any ideas on that?

thanks again.

Nov 22 '05 #3
mtjarrett wrote:
thanks, but i've tried that:
echo $_SESSION['info'][0] . "<br/>";
echo $_SESSION['info'][1] . "<br/>";

it seems that though $_SESSION['info'] is a set it only contains the
word "Array". any ideas on that?

thanks again.


That's what you get if you just echo $_SESSION because it is an array.

Try

print_r($_SESSI ON);
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6857
by: Pedro Fonseca | last post by:
Greetings everyone! I'm porting everything to PHP5. I have session variables in all of my web application. Until PHP5 I was using session variables like: if ($_SESSION == 'Bar') { $value = 5; } $_SESSION is of course set on some other script. But this now
6
12765
by: ASPfool | last post by:
Hello everyone, Please help me before I throw my computer out of the window: I'm working on a web application in classic ASP (vbscript), which is making calls to some webservices. The calls are made using SOAP - i installed the SOAP3 toolkit on my windows 2k server to enable this. The webservice calls are returning String Arrays which I can't seem to do anything useful with. The call shown below returns a string array with two...
27
4239
by: Daniel Lidström | last post by:
Hello! I want to work with individual bytes of integers. I know that ints are 32-bit and will always be. Sometimes I want to work with the entire 32-bits, and other times I want to modify just the first 8-bits for example. For me, I think it would be best if I can declare the 32-bits like this: unsigned char bits;
1
1601
by: Jason Bell | last post by:
Every example of properties I've seen have used simple types such as integers and strings. Here's the scenario I'm trying to work out (3D graphics programming): I have a class called Matrix16f, containing 16 floats that define the matrix, which in turn defines an object's position and orientation in 3D space. As well I want it to have a "position" property, which is a 3D vector that sets the Position values of the matrix.
3
987
by: Bob Altman | last post by:
Hi all, In unmanaged C++, I need to allocate an "array" of int values, put values into the array, then call a function and pass it the address and length of the array. The length of the array is only known at run-time, so I assume that my best course of action is to use a std::vector object for the "array". My question is, am I guaranteed that the vector stores its data in contiguous memory, so that I can use vector.begin() as a...
7
3821
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a database search that I am unable to figure out how to access. (The search is implemented in Php/MySQL.) The user enters search values for: name, address1, city, .... etc., ..... and for each of these they also select whether the search should...
6
10425
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to group by using a two dimensional array. <form name=msgs>
4
2482
by: vanderr | last post by:
Hi everyone. I've recently been asigned a program where we are required to create a 2D array dynamically and then do stuff with it. We are not allowed to "cheat" and use the 1D method. in the constructor of my class i have defined the array as: //GamePiece is a different user defined class, size is an integer passed to the constructor and handle is the name of the 2D array handle = new GamePiece*; for(i=0;i<size;i++) { handle =...
16
6800
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
0
9663
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
9511
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
10404
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...
1
10136
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
9979
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...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
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.