Forum Moderators: coopster
In my index.php, have if statement. default is check user password (function login()), if match, then will retrieve user id from DB.
if (!$_REQUEST['Submit']) {
login();
} elseif ($_REQUEST['Submit'] == "AAA") {
AAA();
}elseif ($_REQUEST['Submit'] == "BBB") {
BBB();
}
function AAA(){
//something here
}
function BBB(){
//something here
}
So, what I want to do is I want the 'id' to be use in every function (AAA, BBB)...I have tried to assign it as global variable at the beginning of page, then echo in function AAA(), but it not work. What is my mistake? Anyone can help? Anyway to do it? Where can I get this type of example or tutorial?
Thanks in advenced.
if you did:
global $id;
function AAA()
{
echo $id;
}
then it will not work.
Use the suggestion by dreamcatcher. However I would recomend using the second option.
Why?
function AAA()
{
global $id;
$id++;
echo "ID+1 = $id<br />";
}
$id = 2;
AAA();
echo "Id = $id";
However
function AAA($id)
{
$id++;
echo "ID+1 = $id<br />";
}
$id = 2;
AAA($id);
echo "Id = $id";
Regards
Michal