PHP数组返回

发布于 2024-11-07 05:42:38 字数 886 浏览 1 评论 0原文

好的,功能:

function session_login_name($username) {
                global $myDB;
                global $config;
                $query = "SELECT /* page == login, functions.php */id, username FROM members WHERE username = '".$username."' LIMIT 1";
                $result = $myDB->Execute($query) or die(GetDbError($myDB->ErrorMsg()));
                $nick_show = $result->Fields("username");
                $nick_id = $result->Fields("id");
                $arr = array($nick_show, $nick_id);
                return $arr;
}

在下一个文件中我需要描述:

$_SESSION['userid'] = ;   //user id
$_SESSION['username'] = ; //user name

我该怎么做? 如果问题不清楚,就说出来...... 哦,print_r ($arr) 给出: Array ( [0] => Zero [1] => 4 )

我已经尝试过(猜测),但这当然是不正确的:/

echo session_login_name($username[0]);
die();

Ok, function:

function session_login_name($username) {
                global $myDB;
                global $config;
                $query = "SELECT /* page == login, functions.php */id, username FROM members WHERE username = '".$username."' LIMIT 1";
                $result = $myDB->Execute($query) or die(GetDbError($myDB->ErrorMsg()));
                $nick_show = $result->Fields("username");
                $nick_id = $result->Fields("id");
                $arr = array($nick_show, $nick_id);
                return $arr;
}

In next file i need describe:

$_SESSION['userid'] = ;   //user id
$_SESSION['username'] = ; //user name

How do I do that?
If question unclear, just say it...
Oh, and print_r ($arr) gives: Array ( [0] => zero [1] => 4 )

I have tried (guessed), but that of course isn't correct :/

echo session_login_name($username[0]);
die();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无人问我粥可暖 2024-11-14 05:42:38

你说 print_r ($arr) 给出: Array ( [0] => Zero [1] => 4 ) 所以你只需要获取这些值并将它们分配给会话变量:

// ToDo: fix SQL injection vulnerability in your SQL
$Data = session_login_name($username);
$_SESSION['userid'] = $Data[1];   //user id
$_SESSION['username'] = $Data[0]; //user name

You said print_r ($arr) gives: Array ( [0] => zero [1] => 4 ) so you just need to get those value and assign them to the session variables:

// ToDo: fix SQL injection vulnerability in your SQL
$Data = session_login_name($username);
$_SESSION['userid'] = $Data[1];   //user id
$_SESSION['username'] = $Data[0]; //user name
兮颜 2024-11-14 05:42:38
$nick_show = $result->Fields("username");
$nick_id = $result->Fields("id");
$arr['userid'] = $nick_id;   //user id
$arr['username'] = $nick_show; //user name
return $arr;
$nick_show = $result->Fields("username");
$nick_id = $result->Fields("id");
$arr['userid'] = $nick_id;   //user id
$arr['username'] = $nick_show; //user name
return $arr;

好吧,你不能回显一个数组,它会在屏幕上打印 array()

你在哪里定义了 $username ?

简单地读取数组的值

well you cant echo an array it will print array() on the screen

where did you define $username ?

well simply read the values of the array

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文