title: getting id from button to a isset post in php
body: <p>In my app I have some buttons, when I click, it saves data to a mysql database, and it works.
  The problem is, that I have 10-15 pages, where I need to save some data, so instead of having 10-15 php page, that save the data in mysql, I want to use one.</p>
  
  <p>this is what worked</p>
  
  <p>My button</p>
  
  <pre><code>    mSubmit = (Button)findViewById(R.id.submit);
      mSubmit.setOnClickListener(this);
  </code></pre>
  
  <p>and my php</p>
  
  <pre><code>if (!empty($_POST)) {
  //initial query
  $query = "INSERT INTO comments ( username, title, message ) VALUES ( :user, :title, :message ) ";
  
  //Update query
  $query_params = array(
      ':user' =&gt; $_POST['username'],
      ':title' =&gt; $_POST['title'],
      ':message' =&gt; $_POST['message']
  );
  </code></pre>
  
  <p>my java</p>
  
  <pre><code>package overskov.rhkbrand;
  
  
  
  
  @SuppressLint("SimpleDateFormat")
  public class AddComment extends Fragment {  
  
  private EditText lys, skilt, door, etDate;
  private Button  mSubmit;
  
    // Progress Dialog
  private ProgressDialog pDialog;
  
  // JSON parser class
  JSONParser jsonParser = new JSONParser();
  
  //php login script
  
  //localhost :  
  //testing on your device
  //put your local ip instead,  on windows, run CMD &gt; ipconfig
  //or in mac's terminal type ifconfig and look for the ip under en0 or en1
  // private static final String POST_COMMENT_URL = "http://xxx.xxx.x.x:1234/webservice/addcomment.php";
  
  //testing on Emulator:
  private static final String POST_COMMENT_URL = "http://overskov-hansen.dk/addcomment.php";
  
  //testing from a real server:
  //private static final String POST_COMMENT_URL = "http://www.mybringback.com/webservice/addcomment.php";
  
  //ids
  private static final String TAG_SUCCESS = "success";
  private static final String TAG_MESSAGE = "message";
  
  
  
  
  
  
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.opgang_a, container, false);              
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      //setContentView(R.layout.add_comment);
      lys =(EditText) rootView.findViewById(R.id.lys);        
      skilt = (EditText)rootView.findViewById(R.id.skilt);
      door = (EditText)rootView.findViewById(R.id.door);
      etDate = (EditText)rootView.findViewById(R.id.etDate);
  
  
  
      //Calendar cal = Calendar.getInstance();
      SimpleDateFormat  format = new SimpleDateFormat("dd.MM.yyyy");  
      try {  
           etDate.setText(format.format(new Date()));
  
  
  } catch (ParseException e) {
          e.printStackTrace();  
      }
  
      mSubmit = (Button)rootView.findViewById(R.id.under_a);
      mSubmit.setOnClickListener(new OnClickListener() {
  
          public void onClick(View arg0) {
              // TODO Auto-generated method stub              
              PostComment mTask = new PostComment(getActivity());
              mTask.execute();                
              //new PostComment().execute();
          }
      });     
      return rootView;
  }
  
  //////////////////////
  
  
  
  class PostComment extends AsyncTask&lt;String, String, String&gt; {
  
  private Context context;
    ProgressDialog prog;
  
    public PostComment(Context context) {
      this.context = context;
    }
  
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(context);
          pDialog.setMessage("Posting Comment...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
      }
  
      @Override
      protected String doInBackground(String... args) {
          // TODO Auto-generated method stub
           // Check for success tag
          int success;
          String post_lys = lys.getText().toString();
          String post_skilt = skilt.getText().toString();
          String post_door = door.getText().toString();
         String post_etDate = etDate.getText().toString();
  
          //We need to change this:
          String post_username = "admin";
  
          try {
              // Building Parameters
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("username", post_username));
              params.add(new BasicNameValuePair("lys", post_lys));
              params.add(new BasicNameValuePair("skilt", post_skilt));
              params.add(new BasicNameValuePair("door", post_door));
          params.add(new BasicNameValuePair("etDate", post_etDate));
  
              Log.d("request!", "starting");
  
              //Posting user data to script
              JSONObject json;                
              json = jsonParser.makeHttpRequest(
                      POST_COMMENT_URL, "POST", params);
  
  
  
              // full json response
              Log.d("Post Comment attempt", json.toString());
  
              // json success element
              success = json.getInt(TAG_SUCCESS);
              if (success == 1) {
                  Log.d("Comment Added!", json.toString());    
                  //finish();
                  return json.getString(TAG_MESSAGE);
              }else{
                  Log.d("Comment Failure!", json.getString(TAG_MESSAGE));
                  return json.getString(TAG_MESSAGE);
  
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
  
          return null;
  
      }
  
      protected void onPostExecute(String file_url) {
          // dismiss the dialog once product deleted
          pDialog.dismiss();
          if (file_url != null){
              Toast.makeText(getActivity(), file_url, Toast.LENGTH_LONG).show();
          } 
      }
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>my php</p>
  
  <pre><code>&lt;?php
  
  //load and connect to MySQL database stuff
  require("config.inc.php");
  
  
  if (isset($_POST['under_a'])) {
  //initial query
  $query = "INSERT INTO under_a ( username, lys, skilt, door, etDate ) VALUES ( :user, :lys, :skilt, :door, :etDate ) ";
  
  
   //Update query
   $query_params = array(
      ':user' =&gt; $_POST['username'],
      ':lys' =&gt; $_POST['lys'],
      ':skilt' =&gt; $_POST['skilt'],
      ':door' =&gt; $_POST['door'],
       ':etDate' =&gt; $_POST['etDate']
  
  
   );
  
  
  //execute query
  try {
      $stmt   = $db-&gt;prepare($query);
      $result = $stmt-&gt;execute($query_params);
  }
  catch (PDOException $ex) {
      // For testing, you could use a die and message. 
      //die("Failed to run query: " . $ex-&gt;getMessage());
  
      //or just use this use this one:
      $response["success"] = 0;
      $response["message"] = "Database Error. Couldn't add post!";
      die(json_encode($response));
  }
  
  $response["success"] = 1;
  $response["message"] = "Post Successfully Added!";
  echo json_encode($response);
  
  }
  
  
  ?&gt; 
  </code></pre>
  
  <p>and my xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" &gt;
  
  &lt;LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="#000000"
    android:orientation="horizontal" &gt;
  
    &lt;TextView
        android:id="@+id/textView1"
        android:layout_width="150dp"
        android:layout_height="35dp"
        android:background="#000000"
        android:paddingLeft="10dp"
        android:text="@string/opgang_a"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#FFFFFF"
        android:textStyle="bold" /&gt;
  
    &lt;EditText
        android:id="@+id/etDate"
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/edit_text_design"
        android:clickable="false"
        android:cursorVisible="false"
        android:ems="15"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="center_vertical|right"
        android:inputType="date"
        android:textColor="#FFFFFF"
        android:textStyle="bold" /&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;ScrollView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_marginTop="30dp" &gt;
  
  &lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="20dp"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/textView2"
           android:layout_width="fill_parent"
          android:layout_height="20dp"
           android:gravity="center_vertical"
      android:paddingLeft="10dp"
      android:textStyle="bold"
      android:textColor="#FFFFFF"
            android:background="#000000"
          android:text="@string/lys" /&gt;
  
      &lt;EditText
          android:id="@+id/lys"
          android:layout_width="fill_parent"
          android:layout_height="30dp"
          android:layout_marginLeft="10dp"
          android:layout_marginRight="10dp"
          android:layout_marginTop="15dp"
          android:text="@string/ok"
          android:textSize="14sp" 
          android:inputType="text"/&gt;
  
        &lt;TextView
            android:id="@+id/textView3"
            android:layout_width="fill_parent"
            android:layout_height="20dp"
            android:layout_marginTop="20dp"
            android:background="#000000"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:text="@string/skilte"
            android:textColor="#FFFFFF"
            android:textStyle="bold" /&gt;
  
  &lt;EditText
      android:id="@+id/skilt"
      android:layout_width="fill_parent"
      android:layout_height="30dp"
      android:layout_marginLeft="10dp"
      android:layout_marginRight="10dp"
      android:layout_marginTop="15dp"
      android:text="@string/ok"
      android:textSize="14sp"
      android:inputType="text" /&gt;
  
        &lt;TextView
            android:id="@+id/textView4"
            android:layout_width="fill_parent"
            android:layout_height="20dp"
            android:layout_marginTop="20dp"
            android:background="#000000"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:text="@string/door"
            android:textColor="#FFFFFF"
            android:textStyle="bold" /&gt;
  
  &lt;EditText
      android:id="@+id/door"
      android:layout_width="fill_parent"
      android:layout_height="30dp"
      android:layout_marginLeft="10dp"
      android:layout_marginRight="10dp"
      android:layout_marginTop="15dp"
      android:inputType="text"
      android:text="@string/ok"
      android:textSize="14sp" &gt;
  
        &lt;requestFocus /&gt;
   &lt;/EditText&gt;
  
  &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  &lt;Button
      android:id="@+id/under_a"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentLeft="true"
      android:background="#000000"
      android:text="@string/gem_data"
      android:textColor="#FFFFFF" /&gt;
  
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>my logcat</p>
  
  <pre><code>02-20 20:51:09.317: E/JSON Parser(19779): Error parsing data org.json.JSONException: End of input at character 2 of  
  </code></pre>
  
  <p>02-20 20:51:09.322: W/dalvikvm(19779): threadid=13: thread exiting with uncaught exception (group=0x41ad2700)
  02-20 20:51:09.332: E/AndroidRuntime(19779): FATAL EXCEPTION: AsyncTask #1
  02-20 20:51:09.332: E/AndroidRuntime(19779): java.lang.RuntimeException: An error occured while executing doInBackground()
  02-20 20:51:09.332: E/AndroidRuntime(19779):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
  02-20 20:51:09.332: E/AndroidRuntime(19779):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)</p>