嗨,我是 android 新手,我正在开发一个有登录屏幕的应用程序。
我尝试了很多教程,但我不确定如何将 mysql 数据库连接到我的 android 应用程序。在所有教程中,他们都使用 php 将 android 应用程序连接到数据库。
我想知道的是,我需要在哪里放置 php 文件,以及我需要在哪里以及如何创建 php 文件。
我正在使用 mysql 工作台创建数据库。
我正在使用 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
?>