0
echo $uid; // RETURNS INTEGER VALUE

if (isset ( $_POST ['cashpaid'] )) {
    $queryfinal = "select * from " . $db_prefix . "customer_det
          where `id` = '$uid'"; // UID RETURNS NULL
....

I've tried everything and every combination of globals and super globals that I could think of. There's just no way I can transfer the value over. I pull $uid from a MySQL select and it assigns to an integer value. As you can see at the start of the code, that ending curly brace is the end of an IF statement which contains the value for $uid.

How can I assign the same value to $uid across all scopes?

This has been killing me for about two days. I'm sorry if this seems elementary but it's about to drive me nuts. I tried $GLOBALS['uid'] to no avail.

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
smada
  • 227
  • 1
  • 7
  • 17
  • 3
    If your code appears exactly how you've included it in the question, there's no difference in scope between the time `$uid` is echoed and the time its appended to the query. – FThompson Nov 02 '12 at 19:41
  • @Vulcan, there also is no 'ending curly brace'. I believe he just forgot to paste it. – LSerni Nov 02 '12 at 19:44
  • Na i had an ending curly brace but a mod edited it out – smada Nov 02 '12 at 19:50

1 Answers1

1

You could try with a setter/getter function declared once in the global scope, but it doesn't do much more than accessing GLOBALS anyway.

function globalUid($value = False)
{
    GLOBAL $__uid;
    if (!isset($__uid))
        $__uid = False;
    if (False === $value)
        return $__uid;
    $__uid = $value;
}

Then instead of echoing $uid, try globalUid($uid) and, later, $saved_uid = globalUid();.

But I think it's possible the two scopes are executing across two different calls, so you might need to save the UID in the session variables.

LSerni
  • 55,617
  • 10
  • 65
  • 107