Variables within functions, out?
| From: | James, Yz | Date: | Thu, 01 Feb 2001 22:21:51 +0000 |
| Subject: | Variables within functions, out? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-37730@lists.php.net to get a copy of this message | ||
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";
}
}
}
?>
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.