Bonjour à tous

je voulais faire une authentification dans une BDD MYSQL

voici mes codes:

MainActivity.jaba

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 
package com.example.tourisme;
 
 
import java.util.ArrayList;
import java.util.List;
 
 
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import com.example.a1.R;
import Tourisme.Dialogue;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
 
public class MainActivity extends Activity {
	private Button connexion1;
	private EditText name1,pass1;
	public ProgressDialog progressDialog;
	public  String url,user,pass;
	HttpPost httppost;
	StringBuffer buffer;
	HttpResponse response;
	HttpClient httpclient;
	List<NameValuePair> nameValuePairs;
	ProgressDialog dialog = null;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        connexion1 = (Button) findViewById(R.id.connexion);
		name1 = (EditText) findViewById(R.id.name);
		pass1 = (EditText) findViewById(R.id.pass);
 
 
		connexion1.setOnClickListener(new View.OnClickListener()
		{
 
 
			    public void onClick(View v)
			{
			    	//parseJSON()  ;
			//startActivity(new Intent(MainActivity.this, ville.class)); //Aller à une autre activité
					//WebView wb = (WebView) findViewById(R.id.webView1); // Créer une vue WEB
					//wb.loadUrl("http://arabhardware.net/forum/");
 
 
					AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
 
 
					int usersize = name1.getText().length();
					int passsize = pass1.getText().length();
					if (usersize > 0 && passsize > 0)
					{
						progressDialog.show();
						String user = name1.getText().toString();
						String pass = pass1.getText().toString();
						//doLogin(user, pass);
 
						 new Thread(new Runnable() {
							    public void run() {
							    	login();					      
							    }
							  }).start();
					}
					else
					{
						new Dialogue(alertDialog,1,"User or Password is empty !!");
						//startActivity(new Intent(MainActivity.this, A1.class));
					}
 
 
 
 
 
 
 
			}
 
	    });
 
    }
 
 
   // @Override
    /*public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }*/
 
 
 
     void login(){
 		try{			
 
 			httpclient=new DefaultHttpClient();
 			httppost= new HttpPost("http://127.0.0.1:8080/android_connect/check.php"); // make sure the url is correct.
 			//add your data
 			nameValuePairs = new ArrayList<NameValuePair>(2);
 			// Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
 			nameValuePairs.add(new BasicNameValuePair("username",name1.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
 			nameValuePairs.add(new BasicNameValuePair("password",pass1.getText().toString().trim())); 
 			httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 			//Execute HTTP Post Request
 			response=httpclient.execute(httppost);
 			// edited by James from coderzheaven.. from here....
 			ResponseHandler<String> responseHandler = new BasicResponseHandler();
 			final String response = httpclient.execute(httppost, responseHandler);
 			System.out.println("Response : " + response); 
 			runOnUiThread(new Runnable() {
 			    public void run() {
 			    	name1.setText("Response from PHP : " + response);
 					dialog.dismiss();
 			    }
 			});
 
 			if(response.equalsIgnoreCase("User Found")){
 				runOnUiThread(new Runnable() {
 				    public void run() {
 				    	Toast.makeText(MainActivity.this,"Login Success", Toast.LENGTH_SHORT).show();
 				    }
 				});
 
 				startActivity(new Intent(MainActivity.this, UserPage.class));
 			}else{
 				showAlert();				
 			}
 
 		}catch(Exception e){
 			dialog.dismiss();
 			System.out.println("Exception : " + e.getMessage());
 		}
 	}
 
     public void showAlert(){
 		MainActivity.this.runOnUiThread(new Runnable() {
 		    public void run() {
 		    	AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
 		    	builder.setTitle("Login Error.");
 		    	builder.setMessage("User not Found.")  
 		    	       .setCancelable(false)
 		    	       .setPositiveButton("OK", new DialogInterface.OnClickListener() {
 		    	           public void onClick(DialogInterface dialog, int id) {
 		    	           }
 		    	       });		    	       
 		    	AlertDialog alert = builder.create();
 		    	alert.show();		    	
 		    }
 		});
 	}
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
AndroidManifest.xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.a1"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
 
 	<uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.tourisme.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.example.tourisme.UserPage"/>
 
    </application>
 
</manifest>
ActivityMain.xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background"
    android:windowSoftInputMode="stateVisible|adjustPan" >
 
  <EditText
         android:id="@+id/name"					android:inputType="text"			android:textSize="@dimen/text_size"
         android:layout_width="fill_parent"		android:layout_height="30dp"
         android:layout_marginTop="110dp"	
         android:layout_alignParentLeft="true" />
 
  <TextView
      android:id="@+id/name1"
      android:layout_width="fill_parent"
      android:layout_height="30dp"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:layout_marginTop="80dp"
      android:gravity="center_vertical"
      android:padding="5dip"
      android:text="@string/name1"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="@dimen/text_size" />
 
   <TextView
      android:id="@+id/pass1"
      android:layout_width="fill_parent"
      android:layout_height="30dp"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:layout_marginTop="140dp"
      android:gravity="center_vertical"
      android:padding="5dip"
      android:text="@string/pass1"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="@dimen/text_size" />
 
    <EditText
         android:id="@+id/pass"					android:inputType="textPassword"			android:textSize="@dimen/text_size"
         android:layout_width="fill_parent"		android:layout_height="30dp"
         android:layout_marginTop="170dp"	    android:layout_alignParentLeft="true" />
 
    <Button
        android:id="@+id/connexion"
        android:layout_width="fill_parent"
        android:layout_height="35dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="220dp"
        android:gravity="center_vertical|center_horizontal"
        android:padding="5dip"
        android:text="@string/connexion"  android:textSize="@dimen/text_size"  />
 
</RelativeLayout>
et voici mon fichier de connexion avec la base ( je l'ai créé dans un dossier dans www de EasyPHP)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
<?php
$hostname_localhost ="localhost";
$database_localhost ="androidhive";
$username_localhost ="root";
$password_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
 
mysql_select_db($database_localhost, $localhost);
 
$username = $_POST['username'];
$password = $_POST['password'];
$query_search = "select * from tbl_user where username = '".$username."' AND password = '".$password. "'";
$query_exec = mysql_query($query_search) or die(mysql_error());
$rows = mysql_num_rows($query_exec);
//echo $rows;
 if($rows == 0) { 
 echo "No Such User Found"; 
 }
 else  {
	echo "User Found"; 
}
?>
Mais j'ai toujours ce problème:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
 The Application has stopped enexpectedly