473,507 Members | 8,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with global variables

Hi All,

I'm turning mad with global variables...
In created a simple test script with 2 functions which worked fine but the
other one i need doesn't work. Register_globals is On.

Here are the relevant parts of my script:
//Save form data in an array
function add_ota_elements($form_data)
{
$otavars = $GLOBALS["otavars"];
$otavars[ota_name] = $form_data[name];
}
function create_new_gprs_dialup()
{
$otavars = $GLOBALS["otavars"];
echo $otavars[ota_name]; //To see if the form data is well saved
}

switch ($action)
{
case add_ota_elements:
add_ota_elements($form_data);
break;
case create_new_gprs_dialup:
create_new_gprs_dialup();
break;
}

$otavars[ota_name] in the second function is empty. Can anybody explain to
me why it is so. I guess it is related to the switch instruction but i
can't understand why.

Thanks in advance for you help.
Stephane
Jul 17 '05 #1
4 4293
Stephane Pointu schrieb:
Hi All,

I'm turning mad with global variables...
In created a simple test script with 2 functions which worked fine but the
other one i need doesn't work. Register_globals is On.

Here are the relevant parts of my script:
//Save form data in an array
function add_ota_elements($form_data)
{
$otavars = $GLOBALS["otavars"];
$otavars[ota_name] = $form_data[name];
}
function create_new_gprs_dialup()
{
$otavars = $GLOBALS["otavars"];
echo $otavars[ota_name]; //To see if the form data is well saved
}

switch ($action)
{
case add_ota_elements:
add_ota_elements($form_data);
break;
case create_new_gprs_dialup:
create_new_gprs_dialup();
break;
}

$otavars[ota_name] in the second function is empty. Can anybody explain to
me why it is so. I guess it is related to the switch instruction but i
can't understand why.

Thanks in advance for you help.
Stephane


The second function is called if the $action is set to
"create_new_gprs_dialup". This function does not fill the $otavars with
the values from the form as the first function do.

I assume that add_ota_elements() is not called in this case.

When $otavars should be filled in this case? Have you stored the
$otavars into a session? Don't forget that any variable is lost after
the server finished your script, if you didn't save them into a session!

HTH!
Rainer
--
------------------------------------------------
Rainer Herbst Linux - Registered
ZEIK User #319157
Universität Potsdam Usual disclaimers applies!
------------------------------------------------

Jul 17 '05 #2
Le Fri, 19 Sep 2003 11:48:24 +0200, Rainer Herbst a écrit*:
The second function is called if the $action is set to
"create_new_gprs_dialup". This function does not fill the $otavars with
the values from the form as the first function do.

I assume that add_ota_elements() is not called in this case.

When $otavars should be filled in this case? Have you stored the
$otavars into a session? Don't forget that any variable is lost after
the server finished your script, if you didn't save them into a session!


I did not put the variable into a session. I thought that i did not have
to as i call the same script... I did not realize that there were two
transactions. Thanks for your answer.

Stephane
Jul 17 '05 #3
Stephane Pointu wrote...
//Save form data in an array
function add_ota_elements($form_data)
{
### create a local scope (for this function) variable
### named otavars and set its value to the current
### value of $GLOBALS["otavars"]
$otavars = $GLOBALS["otavars"];
### if it doesn't exist create the index ota_name
### (did you forget the quotes?)
### of the local otavars and set its value to
### the value of form_data[name]
### again ... did you forget the quotes?
$otavars[ota_name] = $form_data[name];
### why don't you simply do
### $GLOBALS["otavars"][ota_name] = $form_data[name];
### ?
### or with quotes
### $GLOBALS["otavars"]["ota_name"] = $form_data["name"];
}
function create_new_gprs_dialup()
{
$otavars = $GLOBALS["otavars"];
echo $otavars[ota_name]; //To see if the form data is well saved
### echo $GLOBALS["otavars"][ota_name];
}

Jul 17 '05 #4
On Fri, 19 Sep 2003 04:29:07 -0500, Stephane Pointu created an award-winning
crop circle
<pa****************************@free.fr>, which, when translated into
English, means this:
Hi All,

Hello
I'm turning mad with global variables...
In created a simple test script with 2 functions which worked fine but the
other one i need doesn't work. Register_globals is On.

Here are the relevant parts of my script:
//Save form data in an array
function add_ota_elements($form_data)
{
$otavars = $GLOBALS["otavars"];
$otavars = & $GLOBALS["otavars"];
[...]


http://uk2.php.net/ref.references.php

Jul 17 '05 #5

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

Similar topics

3
2803
by: Gary | last post by:
I am having a strange problem that I cannot solve. I have an asp page that I use for a user to login and gain access to other pages. When the user logs in I set a couple of session variables like...
10
17831
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can...
4
24159
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
2
2164
by: Anand Subramanian | last post by:
Hi, Can someone explain the differences(setup, pre-main() setup/initialization) between global variables in a C++ and a C program? The global variables I used are uninitialized. I have a test.o...
2
5169
by: Bryan Parkoff | last post by:
….I would like to know which is the best optimization to use global variable or global struct. I always tell C/C++ Compiler to turn on optimization. ….I use underscore between first name and...
2
4427
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
4
2326
by: Harry | last post by:
Good Day, I am writing a code for the H.264 Video codec.I am using VC++ compiler,but programming is in c only.I have grouped the related global variables under one structure in a header file...
2
3135
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
3
1625
by: =?Utf-8?B?dGhlamFja29mYWxs?= | last post by:
I have a few global variables and a function that gets called multiple times to complete a single transaction and uses the variables. The function gets different notifications. When the function...
2
225
by: Anthony Kuhlman | last post by:
Pythoners, I'm having trouble understanding the behavior of global variables in a code I'm writing. I have a file, test.py, with the following contents foo = def goo(): global foo foo = ...
0
7313
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,...
0
7372
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...
0
7481
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...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
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 ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
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...

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.