473,666 Members | 1,996 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_global s is On.

Here are the relevant parts of my script:
//Save form data in an array
function add_ota_element s($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_element s:
add_ota_element s($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 4301
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_global s is On.

Here are the relevant parts of my script:
//Save form data in an array
function add_ota_element s($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_element s:
add_ota_element s($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_gpr s_dialup". This function does not fill the $otavars with
the values from the form as the first function do.

I assume that add_ota_element s() 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_gpr s_dialup". This function does not fill the $otavars with
the values from the form as the first function do.

I assume that add_ota_element s() 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_element s($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_global s is On.

Here are the relevant parts of my script:
//Save form data in an array
function add_ota_element s($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
2812
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 Session("UserType") = "Sales". Then based on the Session("UserType") I use response.redirect to take the user to a specific page. The logic and response.redirect works fine on a Win2k server but when I move the page to a server running Win2003 the...
10
17857
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 overwrite another copies global variable? I know that you could overwrite a value in a global variable from a function, but you could also do that if you pass the variable in and then out again... so how is that any different?
4
24171
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(); function loadUrlVariables() { varString = location.search;
2
2171
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 which declares a global int " int xxx;". Now I link test.o to a FreeBSD kernel module which then tries to access xxx. If test.o was compiled from C source the kernel can access the global variable (which should be of course its own copy in kernel...
2
5180
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 second name for better readable. After optimization, global variables might be misaligned because each global variables must be converted to 32 bits, but I do see that C/C++ Compiler do padding between variables. Struct does the same to do padding....
2
4444
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 */ #include <time.h>
4
2340
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 called global.h.Like this i have two three structures in global.h. To initialise the structure members in global.h,I declared structure variables in c files wherever the structure members are used.
2
3147
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 then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early as possible .. I am waiting for ur quick replay ...Here i attached the source code .... <!DOCTYPE...
3
1637
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 receives a final notification, that where I need to release the global variables. I don't have control over when the function gets called because the function is called by the system. How can I block the function so that it can only be entered...
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 = foo.append(2)
0
8445
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
8871
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
8551
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
8640
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
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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
2
1776
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.