470,870 Members | 1,396 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

problem with user's login name

hi,

i've a trouble with a php script:

[..]

$uname[1] = "test";
$upass[1] = "test";
$known_as[1] = "test user";

[..]

// check through all the users to see if they exist
for ($i = 1; $i <= $user_count; $i++) {
if ($uname[$i] == $username && $upass[$i] == $password){
$user_id=$i;
$welcome = $known_as[$i];
$user_exists = true;
}

[..]

Now is the main problem: if i call the $welcome var in the logged
page, it won't print the user name... why?

I use:

print($welcome);

and doesn't work...
but if I use:

print($known_as[1]);
it work, but only print the 1 name...

can u help me? tnx in advance! bye!
-Europe-
Jul 17 '05 #1
2 1411
Roby wrote:
Now is the main problem: if i call the $welcome var in the logged
page, it won't print the user name... why? (snip) can u help me? tnx in advance! bye!


Probably your variables are out of scope
http://www.php.net/manual/en/languag...bles.scope.php
<?php
function foo() {
// notice (undefined variable: a) on next line
echo $a; // local $a (to the foo() function)
}

function bar($a) {
echo $a; // local $a -- different than the global $a
}

function taz() {
global $a;
echo $a; // NOW the same $a as previously defined
}

$a = 'global';
$b = 'also global';

echo $a; // use the global and print "global"
foo(); // prints nothing (except perhaps the notice)
bar($a); // prints "global", but it's just a coincidence
bar($b); // prints "also global"
taz(); // prints "global"
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
ok i'll try it now! thank you!
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Bartosz Wegrzyn | last post: by
1 post views Thread by farooqazeem | last post: by
11 posts views Thread by ElmoWatson | last post: by
1 post views Thread by Andrew | last post: by
7 posts views Thread by Samuel Shulman | last post: by
10 posts views Thread by SAL | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.