score:1
connecting android to server using php is best way ...
first use name value pair
public void registeruser(string email, string password, string mobile) {
// building parameters
list<namevaluepair> params = new arraylist<namevaluepair>();
params.add(new basicnamevaluepair("tag", register_tag));
params.add(new basicnamevaluepair("keyemail", email));
params.add(new basicnamevaluepair("keypassword", password));
params.add(new basicnamevaluepair("keymobile", mobile));
// getting json object
jsonparser.makehttprequest(registerurl,params);
}
use json to send the data
public jsonobject makehttprequest(string url,
list<namevaluepair> params) {
// making http request
try {
// request method is post
// defaulthttpclient
defaulthttpclient httpclient = new defaulthttpclient();
httppost httppost = new httppost(url);
httppost.setentity(new urlencodedformentity(params));
httpresponse httpresponse = httpclient.execute(httppost);
httpentity httpentity = httpresponse.getentity();
is = httpentity.getcontent();
} catch (unsupportedencodingexception e) {
e.printstacktrace();
} catch (clientprotocolexception e) {
e.printstacktrace();
} catch (ioexception e) {
e.printstacktrace();
}
try {
bufferedreader reader = new bufferedreader(new inputstreamreader(
is, "iso-8859-1"), 8);
stringbuilder sb = new stringbuilder();
string line = null;
while ((line = reader.readline()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.tostring();
} catch (exception e) {
log.e("buffer error", "error converting result " + e.tostring());
}
// try parse the string to a json object
try {
jobj = new jsonobject(json);
log.d("parser", "in try parse the string to a json object");
} catch (jsonexception e) {
log.e("json parser", "error parsing data " + e.tostring());
}
// return json string
return jobj;
}
php code will get this value and use further
// include db connect class
require_once dirname(__file__).'/db_connect.php';
// connecting to db
$db = new db_connect();
$response = array();
$email = $_post['keyemail'];
$password= $_post['keypassword'];
$phone=$_post['keymobile'];
$tag=$_post['tag'];
$result=mysql_query("insert into tablename (register_email,password,mobile) values('$email','$password', '$phone')");
if ($result) {
// successfully updated
$response["success"] = 1;
$response["message"] = "data inserted successfully.";
// echoing json response
echo json_encode($response);
} else {
$response["error_msg"]="error in insertion";
}
?>
Source: stackoverflow.com
Related Query
- How to access SQL server database from an phonegap android app?
- How can i connect to sql server from my android application?
- How to build and deploy a phonegap app from within Android Studio without eclipse
- How do i retrieve the data using JSON from the Remote Database and display in my android app xml file?
- How to get data from SQL Database using bundles, Android
- How to load my app from Eclipse to my Android phone instead of AVD
- How to implement and use google cloud sql in my android app (eclipse)
- How to debug signed Android app from Eclipse?
- How to view SQL database in Eclipse Debug mode for android
- Inspecting android sql database from Eclipse
- Android - How can I view a sql database created in my app? I'm running it on the Android emulator in Eclipse
- How to use the same source from PhoneGap Build and PhoneGap Android project in Eclipse
- How to access an image from tomcat server path
- How to publish an Android app from Android-Studio using a Keystore file generated in Eclipse?
- How to run android app in real device from ubuntu 12.04 OS?
- How do i put data from an SQL Database to a Hashmap?
- How to correct this query in java such it access the variable SequenceId and gets the value of the sequence from database
- Connecting android app to Microsoft SQL server 2008
- Access Wamp Server Database from Eclipse
- how to fetch data from google app engine datastore in android
- Phonegap - Android APP - how do i alter app launcher title
- how can i access Rational Team Concert source code from a 4.0.7 server using eclipse IDE?
- How to connect to online mysql database from Java desktop app
- How i can open a splashtop app from my own app in android
- how can i access the Sqlite database on real android device using DDMS in eclipse juno
- Don't understand how to pass data from Android Activity to HTML UI when using PhoneGap
- Access or open database from external storage in android
- Android app force closed when trying to send POST data from app to server
- How to Sign Android Phonegap App
- how to access android reference guide from eclipse code view?
More Query from same tag
- How to create Servlet 3.0 web application in maven?
- .project file missing in Eclipse but can be seen in Win Explorer
- Eclipse and Mysql Connection Error
- Manipulate values of two Numberpickers Android
- How do I calculate the average by using the get method for class objects?
- autogenerating ant files from template in eclipse
- How to get java editor source code?
- android app is unable to debug in eclipse
- Is there a way to make eclipse report a general "catch (Exception e)" as an error/warning (in java)?
- Combining main project with google maps project
- Is it possible to export eclipse IDE?
- PyDev Package Explorer doesn't show files in Eclipse
- Worklight 6.2 cannot find runtime when opening Worklight Console
- JavaFX FXMLLoader Call to loaded Controller is NULL
- Why does my Java program work in console and not in Eclipse?
- acm.program needs to be included
- Cannot find module with tag 'cocos2dx-v2.2.2' in import path
- Sample settings.xml required
- I Added a jar into my Eclipse project, but still it doesn't import
- Maven not downloading jars for dependencies
- While Connecting files Network error issue in Eclipse
- eclipse actions controlled by a program?
- Mylyn connector for custom webservice
- Eclipse text comparison order
- Eclipse: Getting null display
- How to export code into runnable JAR within eclipse/lib GDX?
- Tomcat STDOUT as Error in Eclipse
- Creating Desktop Application using Netbeans or Eclispse on Mac
- Java Class file showing question mark
- SWT/JFace databinding change background