• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android app & php

Hi All,

I am developing a simple Android app, this app will be linked with a website. i have simple voting system on my website (php), and i would like to let the app to vote from the android app itself and send the data back to the mysql (read & write)

how i can implement this app

regards,
 
Do a httppost as the previous poster said, post to a php script rather than to the db itself ( for security reasons - i.e you wont have to expose your connection string to the app)
 
What I meant is how to query from android app as the database is mysql and it hosted on the server, for example if I chose an option from radio buttons and I pressed a button in the app, how I am going to store the value in the mysql database? A code example will be helpful
 
What I meant is how to query from android app as the database is mysql and it hosted on the server, for example if I chose an option from radio buttons and I pressed a button in the app, how I am going to store the value in the mysql database? A code example will be helpful


1. you need to write the php script which will take a/several POST argument(s).

2. in the script build a sql insert string by concatenating the POST argument with an INSERT statement

i.e $sql = "INSERT INTO table (name,address) values ($_POST['name'],$_POST['address'])";

3. in android store user input in some variable

4. use httppost class and associated classes to send the data to the php script. Tip: also look at class BasicNameValuePair..this is how you build your post value pairs, i.e name = 'steve', address='the moon'

5. Upon recieving the data the script inserts the data into the mysql

If you cant make sense of this then you should read around the subject as there is actually more involved in creating the httppost than a simple one liner! Same goes in the php script with the actual insertion. For example you want to echo a response back from the script to your android dont you?

Try to create the php side of things first and use curl to test it, sending POST values to it and checking if the insert is successful, that way when you come to the android side of things you know that the php script is working.
Hope this helps.
 
Back
Top Bottom