php - 使用mysql数据库的Android登录 Activity

标签 php android mysql phpmyadmin

您好,我是 Android 新手,我正在开发一个具有登录屏幕的应用。

我试过很多教程,但我不确定如何将 mysql 数据库连接到我的 android 应用程序。在所有教程中,他们都使用 php 将 android 应用程序连接到数据库。

我想知道的是,我究竟需要将 php 文件放在哪里,以及我需要在哪里以及如何创建 php 文件。

我正在使用 mysql workbench 创建数据库。

我正在使用 eclipse 4.2 编写 java 代码。

您好,我正在使用以下代码来检查我输入的用户名是否正确以及 php 代码,但问题是它总是提供不正确的用户名。

String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://192.168.3.27/abc/check.php", postParameters);  //Enetr Your remote PHP,ASP, Servlet file link
String res=response.toString();
// res = res.trim();
res= res.replaceAll("\\s+","");
//error.setText(res);
error.setText(res);
if(res.equals("1")){
    Intent myIntent = new Intent(LoginActivity.this, HomeActivity.class);           
startActivity(myIntent);

}
else
error.setText("Sorry!! Incorrect Username or Password");

这是我的 php 代码。

<?php
$un=$_POST['username'];
$pw=$_POST['password'];
//connect to the db
$user = ‘root’;
$pswd = ‘root’;
$db = ‘mylogin’;
$conn = mysql_connect(‘localhost’, $user, $pswd);
mysql_select_db($db, $conn);
//run the query to search for the username and password the match
$query = “SELECT * FROM userpass WHERE login_id = ‘$un’ AND login_pass = ‘$pw’”;
$result = mysql_query($query) or die(“Unable to verify user because : ” . mysql_error());
//this is where the actual verification happens
if(mysql_num_rows($result) > 0)

echo 1;  // for correct login response
else
echo 0; // for incorrect login response
?>

最佳答案

Here是您正在搜索的完整教程..

就像您的普通 html 页面一样,将登录值从 android 设备发布到 url 并像示例一样在 php 文件中进行身份验证

关于php - 使用mysql数据库的Android登录 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14352125/

相关文章:

android - 在应用程序中检测 Google Play 来源

php - PHP/MySQL 文件/数据库同步的神秘 503 错误

php - 本地主机 php_network_getaddresses : getaddrinfo failed: No such host is known

php - SQLSTATE[42000] : Syntax error or access violation: 1055 for groupby in laravel

php - 在 const 中使用 const

php - 如何为动态生成的字段创建规则

php - 按名称而不是按 2 个日期之间的日期对 sql 请求中的相同行进行排序

php - 使用透明登录过程跨多个站点进行相同登录

android - 如何升级titanium studio中的ti.cloudpush

android - java.lang.IllegalStateException : attempt to re-open an already-closed object: android. 数据库.sqlite.SQLiteQuery