1. Are you ready for the Galaxy S20? Here is everything we know so far!

Apps Problem using Emulator to update MySQL Table on Windows 7, using PHP and Apache Server

Discussion in 'Android Development' started by GraemeLeech, Feb 20, 2011.

  1. GraemeLeech

    GraemeLeech Lurker
    Thread Starter

    Hey folks, I have a problem trying to use an Android App I developed using Eclipse Helios to connect to a MySQL Database and run a PHP File through the emulator. I am not getting an error with this code, but the Table is not updating.

    The PHP File is working properly as when I run it through Internet Exlporer it updates the table in MySQL.

    Please find the code for my App below. The App actually worked once but since then it hasn't been working.

    package com.test.helloworld;

    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import android.app.Activity;
    import android.widget.*;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.*;

    public class HelloWorldApp extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button yes_button = (Button) findViewById(R.id.button);
    yes_button.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    // Connect to Server and update the MY_TABLE DB;
    try
    {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://localhost:3128/YES_BUTTON.php");
    httpclient.execute(httpPost);
    }
    catch(Exception e)
    {
    Log.e("log_tag", "Error in updating MY_TABLE DB"+e.toString());
    }

    }
    });
    }
    }


    Any help would be appreciated, I think it might be an issue with the configuration files as the code seems to be ok. Im using Apache 2.2, PHP 5.3.5 on a Windows 7 machine. I am getting no errors with this code, but my table does not update. It happened once and I cant work out why it wont happen again. If I copy the line :"http://localhost:3128/YES_BUTTON.php into my browser the table gets updated, no problem! But if I run the above code, nothing happens. Any help or guidance would be hugely helpfull, if you have experienced this problem before, Is there some issues with using 'localhost' through the emulator? Even though they are running on the same maching? Should I use REST/SOAP or are they not recommended? Any help would be great guys, I think it's just a small step I am not aware of!!!!
     

    Advertisement

  2. miXer

    miXer Android Enthusiast

    Have you checked the php log?
     
Loading...
Similar Threads - Problem using Emulator
  1. Spyros_B
    Replies:
    5
    Views:
    188
  2. Sidney Menough
    Replies:
    1
    Views:
    265
  3. spman
    Replies:
    8
    Views:
    405
  4. MoodyBlues
    Replies:
    25
    Views:
    1,204
  5. markdoc
    Replies:
    0
    Views:
    135
  6. seamonster515
    Replies:
    1
    Views:
    3,307
  7. Gonchediess1970
    Replies:
    0
    Views:
    293
  8. Ajay_Kumar99
    Replies:
    3
    Views:
    557
  9. oldun
    Replies:
    0
    Views:
    965
  10. Ciortea Razvan
    Replies:
    3
    Views:
    453

Share This Page

Loading...