dqwn64004 2012-05-18 10:40
浏览 19
已采纳

too long

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条回答 默认 最新

  • duanpan3166 2012-05-18 10:54
    关注

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

    $sql=mysql_query("INSERT INTO members (maths)VALUES('" . $right_answers . "')");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度