문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top