I have some problem to store arraylist value to mysql database with php. This is some code I have been created.
First, I have some class to store variable its called Constant.java :
public class Constant {
public static final String FIRST_COLUMN = "First";
public static final String SECOND_COLUMN = "Second";
public static final String THIRD_COLUMN = "Third";
public static final String FOURTH_COLUMN = "Fourth";
}
Second, I have been import that class to MainActivity.java like this :
import static com.testing.informationsystem.Constant.FIRST_COLUMN;
import static com.testing.informationsystem.Constant.SECOND_COLUMN;
import static com.testing.informationsystem.Constant.THIRD_COLUMN;
import static com.testing.informationsystem.Constant.FOURTH_COLUMN;
Third, I store my value to arraylist by this way :
btnInsert = (Button) findViewById(R.id.btnInsert);
btnInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
orderValue = txtOrderValue.getText().toString();
price = txtPrice.getText().toString();
valueSpinner = spnProductFocus.getSelectedItem().toString();
HashMap temp = new HashMap();
if(orderValue.equalsIgnoreCase("")){
orderValue = "0";
}
if(price.equalsIgnoreCase("")){
price = "1000";
}
double count = Double.parseDouble(orderValue) + Double.parseDouble(price);
total = String.valueOf(count);
if(count.equalsIgnoreCase("")){
count = "0";
}
temp.put(FIRST_COLUMN, valueSpinner);
temp.put(SECOND_COLUMN, orderValue);
temp.put(THIRD_COLUMN, price);
temp.put(FOURTH_COLUMN, total);
list.add(temp);
}
});
Okay, now I have arraylist contains value I saved from button. And now I will send it through out HTTPOST to PHP and store it to mysql. This is my code to post it to PHP.
void saveOrder(){
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://dcmodular.com/saktisetia/mobile/order.php");
nameValuePairs = new ArrayList<NameValuePair>(2);
--nameValuePairs.add(new BasicNameValuePair(arraylist));--
----this is my problem about how to post it to PHP---
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
Log.d("Value : ", response.toString());
HttpEntity entity=response.getEntity();
String feedback = EntityUtils.toString(entity).trim();
Log.d("Feedback : ", feedback);
}
Finally, this is my own php file to store it to mysql databases :
<?php
include('connection.php');
--receive arraylist from httppost--
$query = "insert into order(value1) values(value1)";
$execute = mysql_query($query) or die(mysql_error());
if($execute){
echo "saved";
}else{
echo "failed";
}
?>
That is my code and my problem how to post that arraylist to PHP. Thank you before for your helping.