> -----Original Message-----
> From: James, Yz [mailto:[EMAIL PROTECTED]]
> Sent: 01 February 2001 22:22
> To: [EMAIL PROTECTED]
> Subject: Variables within functions, out?
> 
> 
> Hey guys.  Can I firstly say, thanks to all of you who helped 
> me out with my
> last question about importing MS Access databases into 
> MySQL...  It helped
> tons!
> 
> However, I have another question.
> 
> Firstly, I've strayed away from writing many of my own 
> functions, because
> they give me the fear.  But the code on the pages I am 
> creating has forced
> me to wake up...  I really sould think about cutting back on code.
> 
> SO, anyway, to cut to the chase, my question is this:  If I write a
> function, which performs checks and assigns variable based on 
> these checks,
> how do I get the assigned variables from within the function? 
>  For example
> (this is more than likely VERY wrong), something like this:
> 
> global.inc:
> 
> <?
> 
> function CheckBirthday() {
>   global $year,$month,$day;
> 
>     if (($day) && ($month) && ($year)) {
>         if (checkdate($day,$month,$year) {
>             $birthday = "$year/$month/$day";
>         } else {
>             $birthday = "Invalid";
>         }
>     }
> }
> 
> ?>
> 

the correct use of a function would be ...
 function CheckBirthday($year,$month,$day) {
 
     if (($day) && ($month) && ($year)) {
         if (checkdate($day,$month,$year) {
             $birthday = "$year/$month/$day";
         } else {
             $birthday = "Invalid";
         };
     };
     return $birthday;
 }

this function can now be used by a calling program without the callong
program needing to know anything about it's internal working.

> File that would update / insert information to a MySQL database:
> 
> <?
> 
> // Connection details here
> 
> require("global.inc");
> 
> CheckBirthday();
> 
> $sql = "UPDATE MyTable
>         SET
>         birthday = \"$birthday\"
>         WHERE id = \"$id\"
>         ";
> 
> // etc
> 
> ?>
> 
> Even when I KNOW that I have included correct values, the 
> $birthday variable
> never shows up outside the function.  It's probably something 
> simple I'm
> missing, as in most cases ;)
> 
> Thanks for your patience,
> 
> James.
> 
> 
>

        Tim Ward
        Senior Systems Engineer

Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to