Question: I was unable to get a value from a function.
While I was going to print the value, its showing the old value "8". It seems function validateInput() is not working.

```
$current_val = "8";
function validateInput() {
        $db = JFactory::getDbo();
    //$search = $this->item->producer;
    $query = " SELECT * FROM aua8l_djc2_after_reg_page ";
    $db->setQuery($query);
    $result = $db->query();
        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
               $curr = $row['type'];
               global $current_val;
                   switch ($curr) {
                    case '1':
                        $current_val = "youtube";
                        return $current_val;
                        //echo $current_val;
                        //return $GLOBALS['current_val'];
                        break;
                    case '2':
                        $current_val = "rdparty";
                        //return $GLOBALS['current_val'];
                        break;
                    case '3':
                        $current_val = "thankyou";
                        //return $GLOBALS['current_val'];
                        break;
                   } 
            }
        }
} 
echo $current_val;

```

Answer: 
Another way of doing it is this:

```
$current_val = "8";

function validateInput() {
    $db = JFactory::getDbo();
    $query = " SELECT * FROM aua8l_djc2_after_reg_page ";
    $db->setQuery($query);
    $result = $db->query();
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $curr = $row['type'];
            global $current_val;
            switch ($curr) {
                case '1':
                    $current_val = "youtube";
                break;
                case '2':
                    $current_val = "rdparty";
                break;
                case '3':
                    $current_val = "thankyou";
                break;
            } 
        }
        return $current_val;
    }
} 

```

Now you can do either 

```
echo validateInput();

```

or 

```
$current_val = validateInput();    

```

and `$current_val` will be what you want.
```
$current_val = "8";
$current_val = validateInput($current_val);

function validateInput($current_val) {
    $db = JFactory::getDbo();
//$search = $this->item->producer;
$query = " SELECT * FROM aua8l_djc2_after_reg_page ";
$db->setQuery($query);
$result = $db->query();
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
           $curr = $row['type'];
           global $current_val;
               switch ($curr) {
                case '1':
                    $current_val = "youtube";
                    return $current_val;
                    //echo $current_val;
                    //return $GLOBALS['current_val'];
                    break;
                case '2':
                    $current_val = "rdparty";
                    //return $GLOBALS['current_val'];
                    break;
                case '3':
                    $current_val = "thankyou";
                    //return $GLOBALS['current_val'];
                    break;
               } 
        }
    }
} 
echo $current_val;

```