![](/img/trans.png)
[英]How can I get the UserID of a person from a split version of their First/Last Name from FullName in PHP?
[英]How can I pass the userID from PHP to Android(Shared Preferences)
我正在制作一个与我的网站共享相同数据库的应用程序。 我在整个活动中都保持登录会话状态,并且可以获取用户名,但是如何从登录用户那里获取用户ID(PK)? 我已经创建了所有表,并且可以通过应用程序和网站与数据库进行通信。 请帮我
// PHP文件
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting values
$email = $_POST['email'];
$password = $_POST['password'];
//Creating sql query
$sql = "SELECT * FROM Utilizadores WHERE email='$email' AND password='$password'";
//importing dbConnect.php script
require_once('connection.php');
//executing query
$result = mysqli_query($con,$sql);
//fetching result
$check = mysqli_fetch_array($result);
//if we got some result
if(isset($check)){
//displaying success
echo "success";
}else{
//displaying failure
echo "failure";
}
mysqli_close($con);
}
// Android文件
public class Config {
//URL to our login.php file
public static final String LOGIN_URL = "http://192.168.1.43/Teste/login.php";
//Keys for email and password as defined in our $_POST['key'] in login.php
public static final String KEY_EMAIL = "email";
public static final String KEY_PASSWORD = "password";
public static final String KEY_ID = "id_utilizador";
//If server response is equal to this that means login is successful
public static final String LOGIN_SUCCESS = "success";
//Keys for Sharedpreferences
//This would be the name of our shared preferences
public static final String SHARED_PREF_NAME = "myloginapp";
//This would be used to store the email of current logged in user
public static final String EMAIL_SHARED_PREF = "email";
//This would be used to store the id of current logged in user
public static final String ID_SHARED_PREF = "id_utilizador";
//We will use this to store the boolean in sharedpreference to track user is loggedin or not
public static final String LOGGEDIN_SHARED_PREF = "loggedin";
}
据我了解,您想检索一个服务器端变量(用户ID)。 如果登录成功,则可以使服务器输出该变量,然后从Android应用解析服务器响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.