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

  • Home
  • SEARCH
  • 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 7953133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:04:18+00:00 2026-06-04T03:04:18+00:00

Posting a variable to the database has been solved. Still need help posting to

  • 0

Posting a variable to the database has been solved. Still need help posting to the correct row.

What i am trying to do is post a variable to the mysql database. The big problem is getting it to be posted to the correct users row. The user that is logged in.

Below is snippet my quiz activity for maths. At the end of the quiz a dialog box appears. the variable right_answers is being submitted to the database.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    userFunctions = new UserFunctions();
   if(userFunctions.isUserLoggedIn(getApplicationContext())){


uestions.length){
            if(qno==6){
                //If all questions have been answered answer Alert Dialog appears, the user can choose to:
                //Submit score
                //Go to main menu without submitting score
                //Retry

                AlertDialog.Builder alertDialog = new AlertDialog.Builder(mathsActivity.this);



                // Submit score button
                alertDialog.setPositiveButton("Submit Score", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    // User pressed YES button. Write Logic Here
                    //Toast.makeText(getApplicationContext(), "Score Submitted",Toast.LENGTH_SHORT).show();
                    //startActivity(new Intent(getApplication(), MathsMenuActivity.class)); 

                        HttpClient httpclient = new DefaultHttpClient();     
                        HttpPost httppost = new HttpPost("http://xxxxxxxxxxxx.com/script.php"); 
                        try { 
                             List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);         
                             nameValuePairs.add(new BasicNameValuePair("right_answers", Integer.toString(right_answers)));         
                             nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));         
                             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

                             HttpResponse response = httpclient.execute(httppost); 

                        } catch (ClientProtocolException e) {         
                             // TODO Auto-generated catch block     
                        } catch (IOException e) {         
                                 // TODO Auto-generated catch block     
                        } 



                }


                });

}

From user function class which is stored in a package library is the following block.

It is used to to get the login status.

public boolean isUserLoggedIn(Context context){
    DatabaseHandler db = new DatabaseHandler(context);
    int count = db.getRowCount();
    if(count > 0){
        // user logged in
        return true;
    }
    return false;
}

Finally here is the php responsible for inserting the right_answers in the appropriate column.

include 'xxxxx/connect.php';

$right_answers = $_POST['right_answers'];

$sql=mysql_query("INSERT INTO members (maths)VALUES('" . $right_answers . "')");

Help would be appreciated!

Thanks

  • 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-04T03:04:19+00:00Added an answer on June 4, 2026 at 3:04 am

    I am pretty sure without testing it you need to do something like this

    $sql=mysql_query("INSERT INTO members (maths)VALUES('" . $right_answers . "')");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display all comments made in certain posting page. All variable calls
When posting back to my controller my model is populated with correct values and
first time posting in StackOverflow. :D I need my software to add a couple
I am trying to retain a selected value in the dropdown after posting the
I put together some VBA code for Outlook 2007 which has been working predominantly
After posting this question MySQL update or insert or die query I've change to
I am trying to transfer a variable from the URL into a contact form
I'm trying to change a variable name in a query string, so it's usable
Shortened Aim: To pass a variable via $.POST to a PHP file (get.php), and
couldn't find similar posts, so posting my own question. I got variable array of

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.