发布变量以更正行

时间:2012-05-18 10:40:46

标签: php android mysql

已经解决了向数据库发布变量的问题。仍然需要帮助发布到正确的行。

我要做的是将变量发布到mysql数据库。最大的问题是将它发布到正确的用户行。登录的用户。

以下是片段我的数学测验活动。在测验结束时会出现一个对话框。变量right_answers正在提交给数据库。

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     
                        } 



                }


                });

}

来自存储在包库中的用户功能类是以下块。

用于获取登录状态。

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

最后,这里是负责在适当的列中插入right_answers的php。

include 'xxxxx/connect.php';

$right_answers = $_POST['right_answers'];

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

帮助将不胜感激!

由于

1 个答案:

答案 0 :(得分:0)

我很确定没有测试你需要做这样的事情

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