gpt4 book ai didi

javascript - 如何使用 AngularJS 获取数据库列?

转载 作者:行者123 更新时间:2023-12-03 09:33:12 25 4
gpt4 key购买 nike

我想从数据库中获取一些数据,但我只能获取用户 ID 名称和电子邮件。我试图获取城市和地址,但没有显示任何内容,并且在控制台中我收到未定义的信息。有人知道我哪里错了吗?

app.js

.run(function ($rootScope, $location, Data) {
$rootScope.$on("$routeChangeStart", function (event, next, current) {
$rootScope.authenticated = false;
Data.get('session').then(function (results) {
if (results.uid) {
$rootScope.authenticated = true;
$rootScope.uid = results.uid;
$rootScope.name = results.name;
$rootScope.email = results.email;
$rootScope.phone = results.phone;
console.log(results.phone);
} else {
var nextUrl = next.$$route.originalPath;
if (nextUrl == '/signup' || nextUrl == '/login') {

} else {
$location.path("/login");
}
}
});
});
});

仪表板.html

UID: {{uid}}
<br/>NAME: {{name}}
<br/>E-MAIL: {{email}}
<br/>PHONE: {{phone}}
<br/>

sql

CREATE TABLE IF NOT EXISTS `customers_auth` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`phone` varchar(100) NOT NULL,
`password` varchar(200) NOT NULL,
`address` varchar(50) NOT NULL,
`city` varchar(50) NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

dbHandler.php

public function getSession(){
if (!isset($_SESSION)) {
session_start();
}
$sess = array();
if(isset($_SESSION['uid']))
{
$sess["uid"] = $_SESSION['uid'];
$sess["name"] = $_SESSION['name'];
$sess["email"] = $_SESSION['email'];
$sess["phone"] = $_SESSION['phone'];
}
else
{
$sess["uid"] = '';
$sess["name"] = 'Guest';
$sess["email"] = '';
$sess["phone"] = '';
}
return $sess;
}

身份验证.php

$app->get('/session', function() {
$db = new DbHandler();
$session = $db->getSession();
$response["uid"] = $session['uid'];
$response["email"] = $session['email'];
$response["name"] = $session['name'];
echoResponse(200, $session);
});

最佳答案

您肯定需要从customers_auth表编辑authentication.php获取用户信息

$app->get('/session', function() {
$db = new DbHandler();
$session = $db->getSession();
// depends on your db connector you should select the user required
//using the id: "$session['uid']".
$user = $db->getOneRecord("select * from customers_auth where uid =".$session['uid']);
$response["address"] = $user['address'];
$response["city"] = $user['city'];
$response["uid"] = $session['uid'];
$response["email"] = $session['email'];
$response["name"] = $session['name'];
echoResponse(200, $response);
});

关于javascript - 如何使用 AngularJS 获取数据库列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31428374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com