gpt4 book ai didi

php - 无法在 Android 中使用 PHP 脚本插入 MySQL

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:49 25 4
gpt4 key购买 nike

我正在尝试使用 Volley 库的 php 脚本将 firebase token_key 插入到 mysql 中,但无法实现它。我面临“AuthFailureError”异常。

我知道我犯了一些错误,但无法弄清楚。我在此处附上代码 fragment ,请给我一些建议:

初始化文件

<?php

$host = "localhost";
$db_user = "root";
$db_password = "*****";
$db_name = "fcmdb";

$con = mysqli_connect($host,$db_user,$db_password,$db_name);
if($con)
echo "Connection Success...";
else
echo "Connection Failure...";

?>

fcm_insert.php

<?php

require "init.php";
$fcm_token ='';
$fcm_token = $_POST["key_token"];
$sql = "insert into fcm_info values('".$fcm_token."');";
mysqli_query($con,$sql);
mysqli_close($con);

?>

主 Activity .java

public class MainActivity extends AppCompatActivity {
private Button btnClick;
String app_server_url="http://192.168.0.106:8079/fcmtest/fcm_insert.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnClick=(Button)findViewById(R.id.button);

btnClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

SharedPreferences sharedPreferences=getApplicationContext().getSharedPreferences(getString(R.string.FCM_PREF), Context.MODE_PRIVATE);
final String token=sharedPreferences.getString(getString(R.string.FCM_TOKEN),"");

StringRequest stringRequest=new StringRequest(Request.Method.POST, app_server_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("Error",response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("Error",error.toString());
}
})

{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params=new HashMap<String, String>();
params.put("key_token",token);

return params;
}
};
MySingleton.getMySingleton(MainActivity.this).addToRequestQueue(stringRequest);
}
});
}
}

最佳答案

嘿嘿,请点击以下链接

对你有帮助

This link for php with android

关于php - 无法在 Android 中使用 PHP 脚本插入 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41894407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com