ok i have made a function to get 2 variables, im having no problem echoing the variables if i place the echo's in the function but if try to echo them from outside the function it won't play ball:

heres my code:

<?php
function Get_Auth_Test()
{
$testserver = "mysql.dth-scripts.com";
$testdb = "files";
$testuser = "admin";
$testpass = "qweasd";
$testtable1 = "Registrations";
$cdir = basename(getcwd());

$testconn = mysql_connect($testserver,$testuser,$testpass);
if (!$testconn) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("$testdb", $testconn) or die("Unable to select database '$testdb'"); 

$testquery = "SELECT * FROM $testtable1 WHERE folder='$cdir'";
$testresult = mysql_query($testquery) or trigger_error("SQL", E_USER_ERROR);

while ($testb = mysql_fetch_array($testresult)){

$testfolder = $testb['folder'];
}
<-- if i place echo's here they work fine?
}

Get_Auth_Test();

echo $testfolder;  /produces didly squat
?>

    It looks like you are missing to return $testfolder to the calling script/function.
    You should add

    return $testfolder;

    in the end of your function

      you have a problem with the scope of your variables, you need to either define them as global or have the function return whatever value you need from it.

      EDIT: I didn't see your post Igor, but yeah I agree.

        ok i have added the return part of the code and there is still not output there?

        i need to return both $cdir and $testfolder

        $testfolder = $testb['folder'];
        }
        return $testfolder; 
        }
        
        Get_Auth_Test();
        
        echo $testfolder;
        ?>

          You can only return 1 variable with return so you need to put the items you are interest in in a array or list or whatever and return that variable.
          Another way is to work with references in the input argument list but i would recommend against.

            8 days later

            you are almost there,

            $testfolder = Get_Auth_Test();
            echo $testfolder;
            ?> 
            
              Write a Reply...