http - Connection Android PHP/MySQL -
when trying establish connection mysql following error.
package com.example.projetoansc; import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; import java.io.unsupportedencodingexception; import java.util.arraylist; import java.util.list; import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.defaulthttpclient; import android.os.asynctask; import android.util.log; public class conexao extends asynctask<string, string, string> { list<namevaluepair> postparams= new arraylist<namevaluepair>(); private string url=null; public conexao(string url, list<namevaluepair> params){ this.postparams = params; this.url = url; } @override protected string doinbackground(string... params) { try{ defaulthttpclient client = new defaulthttpclient(); httppost httppost = new httppost(url); httppost.setentity(new urlencodedformentity(postparams)); httpresponse httpresponse = client.execute(httppost); httpentity httpentity = httpresponse.getentity(); bufferedreader reader = new bufferedreader(new inputstreamreader(httpentity.getcontent())); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } return sb.tostring(); }catch (unsupportedencodingexception e) { e.printstacktrace(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return ""; } } //and class class call object conexao.class public void onclick(view v) { string url = "http://myhost/phpandroid/contexto.php"; arraylist<namevaluepair> parametros = new arraylist<namevaluepair>(); parametros.add(new basicnamevaluepair("nome",edittext1.gettext().tostring())); parametros.add(new basicnamevaluepair("nome",edittext2.gettext().tostring())); try{ string resultado = new conexao(url, parametros).execute().get(); if(resultado.equals(edittext1.gettext().tostring())){ log.i("logar", "resposta = "+ resultado); } else{ log.i("logar", "resposta = "+ resultado); } }catch(exception e){ log.i("logar", "erro = " + e); } }
error in logcat
04-25 18:41:37.447: w/audiotrack(347): audio_output_flag_fast denied client 04-25 18:41:37.937: i/logar(1290): resposta = <br /> 04-25 18:41:37.937: i/logar(1290): <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> 04-25 18:41:37.937: i/logar(1290): <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> notice: undefined index: senha in c:\wamp\www\phpandroid\contexto.php on line <i>7</i></th></tr> 04-25 18:41:37.937: i/logar(1290): <tr><th align='left' bgcolor='#e9b96e' colspan='5'>call stack</th></tr> 04-25 18:41:37.937: i/logar(1290): <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>time</th><th align='left' bgcolor='#eeeeec'>memory</th><th align='left' bgcolor='#eeeeec'>function</th><th align='left' bgcolor='#eeeeec'>location</th></tr> 04-25 18:41:37.937: i/logar(1290): <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0000</td><td bgcolor='#eeeeec' align='right'>244656</td><td bgcolor='#eeeeec'>{main}( )</td><td title='c:\wamp\www\phpandroid\contexto.php' bgcolor='#eeeeec'>..\contexto.php<b>:</b>0</td></tr> 04-25 18:41:37.937: i/logar(1290): </table></font> 04-25 18:41:37.937: i/logar(1290): 04-25 18:41:37.937: i/logar(1290): 04-25 18:41:37.972: i/choreographer(1290): skipped 160 frames! application may doing work on main thread. 04-25 18:49:40.900: i/usagestatsservice(347): user[0] flushing usage stats disk 04-25 18:59:46.709: i/processstatsservice(347): prepared write state in 20ms 04-25 18:59:46.770: i/processstatsservice(347): prepared write state in 4ms 04-25 18:59:46.871: i/processstatsservice(347): pruning old procstats: /data/system/procstats/state-2015-04-20-17-04-33.bin 04-25 19:01:00.011: i/activitymanager(347): killing 757:com.android.music/u0a33 (adj 13): empty 1802s 04-25 19:01:00.132: i/activitymanager(347): killing 693:com.android.printspooler/u0a39 (adj 15): empty 1811s 04-25 19:01:46.852: i/activitymanager(347): killing 1011:com.android.settings/1000 (adj 13): empty 1819s 04-25 19:01:46.976: i/activitymanager(347): killing 961:com.android.managedprovisioning/u0a8 (adj 15): empty 1824s 04-25 19:01:47.044: i/activitymanager(347): killing 923:com.android.dialer/u0a4 (adj 15): empty 1827s 04-25 19:02:00.016: i/activitymanager(347): killing 1088:com.android.exchange/u0a27 (adj 15): empty 1810s 04-25 19:02:00.067: i/activitymanager(347): killing 802:android.process.media/u0a5 (adj 15): empty 1811s 04-25 19:04:47.610: i/art(656): background partial concurrent mark sweep gc freed 4927(338kb) allocspace objects, 0(0b) los objects, 25% free, 1520kb/2032kb, paused 1.151ms total 383.637ms
what happens variable resultado receiving big code html instead datas mysql.
here problem
parametros.add(new basicnamevaluepair("nome",edittext1.gettext().tostring())); parametros.add(new basicnamevaluepair("nome",edittext2.gettext().tostring()));
the 2 params have "nome" thats why "senha" not defined change 1 of them "senha"
Comments
Post a Comment