Remark.java:
This acts like a backgroundworker and posts data through coordinating with my php in my htdocs:
List<NameValuePair> nameValuePairs;
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("input", inputString.trim()));
try {
String Url = "http://192.168.x.x/webservices/scwebservice/"+command+".php";
httpclient = new DefaultHttpClient();
String riddleIDValString = URLEncoder.encode(inputString,"UTF-8");
Url = Url+"?input="+riddleIDValString;
httpost = new HttpPost(Url);
httpost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httpost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data)) ) {
buffer.append(new String(data, 0, len));
}
//for the output or echo
final String bufferedInputString = buffer.toString();
inputStream.close();
((Activity) context).runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(context, bufferedInputString, Toast.LENGTH_SHORT).show();
}
});
}
This is my another java class, it passes the data to my Remarks.java (sample data it passes:"2014102002:myremark"), Im also passing my "UPDATE-REMARK" in the REMARK.java to know the php file to use.
Remark update = new Remark(StudentprofileActivity.this,"UPDATE-REMARK");
switch (arg0.getId()) {
case R.id.btnsave:
update.execute(id+":"+edittextremarks.getText().toString());
break;
}
This is my PHP file in htdocs, it coordinates with my Remarks.java, and receives the input "2014102002:myremark", the php file will explode it and then update column remark in my database (the id is an int, and the remark is varchar):
$link = mysql_connect("localhost", "root", "");
mysql_select_db("my_db", $link);
$remarkinfo = $_POST['input'];
$data = explode(":",$remarkinfo);
$studid=(int)$data[0];
mysql_query("UPDATE attendance_tbl SET remarks = '$data[1]' where student_id = $studid") or die(mysql_error());
echo $remarkinfo;
Im trying to execute my php file in the browser url, it is updating my column but when im trying to run the app in my phone it doesn't update the column. Can you check what's wrong in my Remark.java? Or if i have something to improve in the php file?