저는 Android 스크립트를 배우고 PHP 스크립트와 WAMP 서버를 사용하여 사용자 이름과 비밀번호를 확인하는 코드를 작성하려고합니다. 내 PHP 스크립트에서 정의되지 않은 인덱스 오류가 계속 발생합니다. 늘어나는만큼 내가 확인할 수있는 내 PHP 스크립트 URL에서 데이터를 액세스 할 수 없습니다. 다음은 관련 코드입니다. 어떤 도움을 주셔서 감사합니다. 여기 HTTP Post가 android에서 PHP와 작동하지 않습니다.
//build url data to be sent to server
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username",username));
nameValuePairs.add(new BasicNameValuePair("password",password));
String result = "";
InputStream is = null;
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/PasswordCheck.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("Connection", "Error in http connection "+e.toString());
}
내 PHP 스크립트
여기
<?php
mysql_connect("localhost", "root", "") or die("could not connect to mysql");
mysql_select_db("drop-in") or die("database not found");
$username = $_POST["username"];
$suppliedPassword = $_POST["password"];
$databasePassword = "";
$output = "false";
$query = mysql_query("SELECT Password FROM users WHERE Username = '$username'") or die("query failed");
if(mysql_num_rows($query) > 0){
$row = mysql_fetch_assoc($query);
$databasePassword = $row['password'];
if($databasePassword == $suppliedPassword)
{
$output = "true";
}
}
print($output);
mysql_close();
?>
그리고 서버의 응답
편집의 사진입니다 : 그래서 PHP 스크립트가 제공 되더라도 것을 알아 냈어 이 오류는 $ username과 $ password 변수에 my android 앱이 전달하려고 시도한 값을 포함합니다. 그러나 오류 테이블에 대한 HTML이 응답의 안드로이드 애플 리케이션에 다시 전송되기 때문에 이러한 오류의 존재는 여전히 혼란 스럽다.
ArrayList가 필요에 따라 증가하므로 문제가되지 않습니다. 그래도 고마워. –