I am trying to post a game high-score to my database table, but I cannot figure out how to do this by passing an integer value, only strings. The following is the method I want to call when the game ends, this should insert the score into the score column of my table.
public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://deucalion0.co.uk/insert.php"); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("score", finalscore)); //"score" is the name of the database table, finalscore is the integer that contains the value httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } } I am getting a red line under the parameters "score", finalscore as it tells me it can only take a string, and it knows that final score is an integer.
If I can figure this out, I will then create a way where the user can enter a name via a form input and this will be entered into the user column of the table along with the score. I have searched through Stackoverflow for help with integers and nameValuePairs but could not find anything.
I appreciate any assistance.
Thanks.