dongquanjie9328 2012-10-25 07:39
浏览 41
已采纳

不将我在android中的编辑文本值传递给PHP变量

I'm able to connect into my MySQL database but the problem is. My android does not passing the edit text value to PHP with this codes.

public class MySQL extends Activity {

    EditText inputName;
     private static String  url_create_product = "http://atlantis-us.com/phpFile.php?";

     JSONParser jsonParser = new JSONParser();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_sql);
        inputName = (EditText) findViewById(R.id.txt1);

       ((Button) findViewById(R.id.btnsend)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            new CreateNewProduct().execute();
        }
    });

    }

    class CreateNewProduct extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... arg0) {
            // TODO Auto-generated method stub
            String name = inputName.getText().toString();
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("name", name));
            JSONObject json = jsonParser.makeHttpRequest(url_create_product,
                    "POST", params);

            return null;
        }

    }

}



this is my PHP codes

<?php

    $DB_HostName = "localhost";
    $DB_Name = "_atlantisdb";
    $DB_User = "atlantis_frux";
    $DB_Pass = "frux2012";
    $DB_Table = "testDB";

    if (isset ($_GET["name"]))
        $name = $_GET["name"];
    else
        $name = "Ghalia";

    $con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error()); 
    mysql_select_db($DB_Name,$con) or die(mysql_error()); 

    $sql = "insert into $DB_Table (name) values('$name');";
    $res = mysql_query($sql,$con) or die(mysql_error());

    mysql_close($con);
    if ($res) {
        echo "success";
    }else{
        echo "faild";
    }// end else

?>

can anyone trace what's worng with my codes? thanks in advance.

  • 写回答

1条回答 默认 最新

  • doushupu2521 2012-10-25 07:45
    关注

    You are sending the edit text value using POST method in your android code and getting the value using method GET in your php code.

    chage $_GET["name"] to $_POST["name"] or $_REQUEST['name']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵