0

I am using drupal 6. I have a variable in a function which I saved with variable_set. I called variable_get in a different function and it keeps giving me the default. Why wont it save the variable? I know that the variable has a value because its used in sql query.

here's my set:

    $staff_action = $_GET['staff_action'];
$first_name = $_GET['first_name'];
variable_set('first_name', $first_name);
$last_name = $_GET['last_name'];
variable_set('last_name', $last_name);
$email = $_GET['email'];
variable_set('email', $email);
drupal_set_message($email . " in first function");

here's my get in second function:

$first_name = $_GET['first_name'];
$last_name = $_GET['last_name'];
$email = variable_get('email', 'none found');
drupal_set_message($email . " in second function");
1

In your code where you are setting the value move the last line above variable_set() function

Change this code:

 $staff_action = $_GET['staff_action'];
$first_name = $_GET['first_name'];
variable_set('first_name', $first_name);
$last_name = $_GET['last_name'];
variable_set('last_name', $last_name);
$email = $_GET['email'];
variable_set('email', $email);
drupal_set_message($email . " in first function");

To this:

 $staff_action = $_GET['staff_action'];
$first_name = $_GET['first_name'];
variable_set('first_name', $first_name);
$last_name = $_GET['last_name'];
variable_set('last_name', $last_name);
$email = $_GET['email'];
drupal_set_message($email . " in first function");
variable_set('email', $email);

Then it should work.

| improve this answer | |
  • no, that actually doesn't work. I put that drupal_set_message in after I was already getting errors... But I just tried using the php 'global' command instead, and it still did't give me the email address! I know its there, its used in the query! – user1015214 Apr 25 '12 at 21:42
  • I tested it with drupal_set_message() at the end as you have it. I was not able to get the value but once I moved drupal_set_message() above the variabel_set it worked. This part of the code is working, you might have error in some other part of your code. – 15dk51 Apr 25 '12 at 21:50
  • It should not make any difference, as variable_set() is not influenced from any function that is previously called, if those functions are not altering the variable passed to variable_set(). – kiamlaluno Apr 25 '12 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.