hello everyone I just started programming in android I followed some tutorial, my goal is to connect a terminal android to a remote server php ,this is what I did:
1 - install WampServer
installation directory "C:\wamp"
2 - install php on eclipse
installation directory "C:\eclipse"
3 - configure the Apache httpd.conf
documentroot "C:\Users\ACER\Php Projets"
and directory"C:\Users\ACER\Php Projets"
my problem is that the msg sent from Android client but it does not reach the data base
i follow this tuto http://www.youtube.com/watch?v=BaSkR6boiBc&list=PLD4ADFA5CCDB73707
in the AndroidManifest.xml
<uses-permission android:name=
"android.permission.INTERNET"
/>
<?php
if
( isset($_POST) && !empty($_POST)){
extract($_POST);
$db = mysql_connect(
'localhost'
,
'root'
,
'motdepass'
);
mysql_select_db(
'gsctuto'
,$db);
$sql =
"INSERT INTO information (message) VALUES ('$message')"
;
mysql_query($sql);
}
?>
package
com.example.test;
import
java.io.IOException;
import
java.io.InputStream;
import
java.util.ArrayList;
import
java.util.List;
import
org.apache.http.NameValuePair;
import
org.apache.http.client.ClientProtocolException;
import
org.apache.http.client.HttpClient;
import
org.apache.http.client.entity.UrlEncodedFormEntity;
import
org.apache.http.client.methods.HttpPost;
import
org.apache.http.impl.client.DefaultHttpClient;
import
org.apache.http.message.BasicNameValuePair;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
import
android.widget.EditText;
import
android.widget.Toast;
public
class
MainActivity
extends
Activity {
EditText edtMsg;
Button btnEnvoyer;
String resultat =
null
;
InputStream is =
null
;
StringBuilder sb =
null
;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
edtMsg = (EditText) findViewById(R.id.edtMsg);
btnEnvoyer = (Button) findViewById(R.id.btnEnvoyer);
}
public
void
envoyerMsg(View view){
HttpClient client =
new
DefaultHttpClient();
String msg = edtMsg.getText().toString();
if
(msg.length() >
0
){
try
{
List<NameValuePair> donnees =
new
ArrayList<NameValuePair>(
1
);
donnees.add(
new
BasicNameValuePair(
"message"
, msg));
post.setEntity(
new
UrlEncodedFormEntity(donnees));
client.execute(post);
edtMsg.setText(
""
);
Toast.makeText(
this
,
"message envoyer"
, Toast.LENGTH_SHORT).show();
}
catch
(ClientProtocolException e){
e.printStackTrace();
}
catch
(IOException e){
e.printStackTrace();
}
}
else
{
Toast.makeText(
this
,
"ce champs est vide"
, Toast.LENGTH_SHORT).show();
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment