Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7757927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:13:27+00:00 2026-06-01T13:13:27+00:00

I am using the following code to post data from an android app to

  • 0

I am using the following code to post data from an android app to a PHP script:

public class Upload extends Activity implements OnClickListener {
EditText joke;
Button upload = (Button) findViewById(R.id.bUpload);
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.upload);
    upload.setOnClickListener(this);
}
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.bUpload:
        uploadJoke();
        break;
    }

}
private void uploadJoke() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://xxxx/telejoke.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("username", "test"));
        nameValuePairs.add(new BasicNameValuePair("joke", joke.getText().toString()));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }
}

This code sends data to a PHP script, which then sends it on to an SQL database. This data shows up in the SQL database, but if I try something like echo $username it doesn’t show the username when I go to http://xxxx/telejoke.php.

PHP script:

<?php
  include 'DBConnect.php';
  include 'JokeValidate.php';

  $username = $_POST['username'];
  $joke = $_POST['joke'];
  $dbname = 'Telejoke';
  mysql_select_db($dbname);

  echo $username. " " . $joke;

  if (validate()){
    $query = "INSERT INTO jokes (username, joke) VALUES ('$username','$joke')";
    mysql_query($query) or die('Error, insert query failed');
  }
  mysql_close($conn);
?>

Please help. I want to do things to the posted data with PHP besides just send it on to database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:13:28+00:00Added an answer on June 1, 2026 at 1:13 pm

    I guess register_globals is off (which is fine)!!!

    You have to address username via $_POST[‘username’] (of course in telepost.php).

    OKAY (after you posted your php-script I think I got it).
    You said “after going to http://xxx/telejoke.php i cannot see my username, but the data is uploaded correctly”.

    –> Yeah, that behaviour is correct.
    You do not pass any POST parameters to your php script, so $_POST[‘username’] is empty.

    –> But if you call the script via your application you pass the required POST paramters (username, joke, etc) to your script. So it can write your data correctly in your database.

    In addition you should optimize your SQL/script to prevent SQL injection.
    A bad user may cause damage to your website (e.g. deleting all jokes, etc…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using following code but cannot return data from MySQL. This is the output:
I am using the following code to get data from the database( from cs
I'm using the following code to request data from an ASP.net MVC application. I'm
Im using the following ajax code to submit data from a form to a
I am using following code to get data from the Server and if the
I have a php multidimensional array populated from a table using the following code:
I'm using the following code: <form action= method=post enctype=multipart/form-data> <label for=file>Filename:</label> <input type=file name=file
I'm using the following code to post to the server which is then sent
I'm using the following code to simulate a page post. (I'm subclassing WebClient so
I am successfully posting a form via ajax, using the following code; $.post( Page.do?source=ajax,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.