im developing android cms that synchronize the database from server to client. the interface are already there but, there some bugs that i cannot link to the server
here my coding
when i enter the username, it state that "No username found" but the username are there in the server.
please give me some suggestion on how to debug on this..
this is my FirstTimeUser.php
here my coding
Code:
public void onClick(DialogInterface arg0, int arg1) {
// Get the username from the user
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("Username", UserName.getText().toString()));
String response = null;
try {
response = CustomHttpClient.executeHttpPost(ServerIP+"LMS/LMSscripts/FirstTimeUser.php", postParameters); //Enetr Your remote PHP,ASP, Servlet file link
String res=response.toString().substring(0,1);
// res = res.trim();
res= res.replaceAll("\\s+","");
//error.setText(res);
if(res.equals("1")) {
String GetUsername = UserName.getText().toString();
String UserFile = ServerIP + "LMS/LMSscripts/" + GetUsername + ".txt";
// Make the user directory
File userDirectory = new File(SDroot.concat(GetUsername));
userDirectory.mkdirs();
try {
// Create a URL to read the student's text file
URL url = new URL(UserFile);
// Read all the text returned by the server
// fileName is refer to the name of the file
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String courseCode;
// Create the course directory
while ((courseCode = in.readLine()) != null) {
File courseDirectory = new File(SDroot.concat(GetUsername),"/".concat(courseCode));
courseDirectory.mkdirs();
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
}
else {
//incorrect
// print on the toastbox on the screen
// the button was clicked
Toast.makeText(getApplicationContext(), "No username found!", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
UserName.setText(e.toString());
}
}
});
when i enter the username, it state that "No username found" but the username are there in the server.
please give me some suggestion on how to debug on this..
this is my FirstTimeUser.php
Code:
<?php
$un = $_POST['Username'];
// connect to the db
$mysql_host = "localhost";
$mysql_database = "*****";
$mysql_user = "******";
$mysql_password = "****";
$conn = mysql_connect($mysql_host,$mysql_user,$mysql_password);
mysql_select_db($mysql_database,$conn);
$query = "SELECT * FROM student WHERE Username='$un'";
$result = mysql_query($query);
//Store all the course code into an array
$course_code = mysql_fetch_array($result);
//verification
if(mysql_num_rows($result) == 1) {
echo 1; // for correct login response
$format = ".txt";
$output = $un.$format;
$fh = fopen($output,'w') or die ("Can't open file");
for($num=1;$num<=5;$num++) {
$code = $course_code['Course'.$num];
fwrite($fh,$code."\r\n");
}
chmod($output,0777); //chmod the file to 0777
fclose($fh);
} else {
echo 0; // for incorrect login response
}
?>