Baki BAL
Baki BAL
İstanbul-II (Anadolu)
14/06/2017 tarihinden beri üye
10 GY Puanı
99K GY Sırası

Kişisel Sayfaları

İlgi Alanları

1 Rozet
0 Sertifika
1 Soru Sordu
0 Cevap Verdi
0 Blog Yazısı
0 Etiket Takibi

Hakkında

İş Tecrubesi

Kullanıcıya ait İş tecrübesi bilgisi bulunmamaktadır.

Eğitim Geçmişi

Maltepe Üniversitesi
| Aralık 2020 - Aralık 2020

Sertifikalar & Başarılar

GY Sertifikaları (0)
Kullanıcının GY sertifikası bulunmamaktadır.
Diğer Sertifikaları (0)
Kullanıcıya ait sertifika bulunmamaktadır.
Test Sonuçları (0)

Kullanıcıya ait test sonucu bulunmamaktadır.

Dil Becerileri

Son Forum Aktiviteleri

1
Tümünü Gör

Androidden Mysql'e Veri Gönderirken JSON Hatası

Ben telefon üzerinden aldığım koordinatları online mysql db'sine yollamak istyorum. Ancak loglarda şöyle bir hata alıyorum.

 

06-14 09:19:20.822 28270-28270/com.example.gpstracking E/pass 1: connection success 
06-14 09:19:20.835 28270-28270/com.example.gpstracking E/pass 2: connection success 
06-14 09:19:20.835 28270-28270/com.example.gpstracking E/Fail 3: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

insert.php

<?php
   header("Content-Type: application/json;charset=utf-8");
    $host='bitirmeproje.comeze.com';
    $uname='id1966593_bakibal';
    $pwd='******';
    $db="id1966593_bitirmedb";

    $con = mysql_connect($host,$uname,$pwd,$db) 
    
     
    $latitude=$_REQUEST['latitude'];
    $longitude=$_REQUEST['longitude'];

    $flag['code']=0;

    if($r=mysql_query("insert into koordinat values('$latitude','$longitude') ",$con))
    {
        $flag['code']=1;
                echo json_encode($flag)
    }
        
    mysql_close($con);
?>

Android activity.java


public void insert() {

ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

double latitude = gps.getLatitude();

double longitude = gps.getLongitude();

InputStream is=null;

String result=null;

String line=null;

int code;

nameValuePairs.add(new BasicNameValuePair("latitude",Double.toString(latitude)));

nameValuePairs.add(new BasicNameValuePair("longitude",Double.toString(longitude)));

try

{ HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://bitirmeproje.comeze.com/insert.php");

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);

HttpEntity entity = response.getEntity();

is = entity.getContent(); Log.e("pass 1", "connection success ");

}

catch(Exception e) {

Log.e("Fail 1", e.toString());

Toast.makeText(getApplicationContext(), "Invalid IP Address", Toast.LENGTH_LONG).show(); }

try {

BufferedReader reader = new BufferedReader(new InputStreamReader(is, HTTP.UTF_8),8);

StringBuilder sb = new StringBuilder();

while ((line = reader.readLine()) != null)

{ sb.append(line); } is.close();

result = sb.toString();

Log.e("pass 2", "connection success "); }

catch(Exception e) {

Log.e("Fail 2", e.toString()); }

try {

JSONObject json_data = new JSONObject(result);

code=(json_data.getInt("code"));

if(code==1)

{ Toast.makeText(getBaseContext(), "Inserted Successfully", Toast.LENGTH_SHORT).show(); }

else { Toast.makeText(getBaseContext(), "Sorry, Try Again", Toast.LENGTH_LONG).show(); } }

catch(Exception e) { Log.e("Fail 3", e.toString()); } }
 

6 yıl 10 ay önce yanıtladın