我的应用程序应该将一些数据发送到我的php脚本,然后php脚本将其推送到我的在线数据库。但该应用程序不断发送空值,并使用一个简单的HTML表单尝试我的PHP脚本,它完美地工作并发布到数据库。
使用排球图库还是新手。
这是我的注册类:
private void registerfunc(final String name, final String email, final String phone, final String address) {`
String url ="http://circleincoprated.com/apps/register.php";
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("JSon data... ", response);
if (response.trim().equals("success")) {
pd.hide();
Toast.makeText(first_run.this, "registration Successful", Toast.LENGTH_LONG).show();
Intent in = new Intent(first_run.this, MainActivity.class);
startActivity(in);
} else {
pd.hide();
Toast.makeText(first_run.this, "registration Failed" + response, Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pd.hide();
Log.d("JSon Error... ", error.toString());
Toast.makeText(first_run.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
//Creating parameters
Map<String, String> params = new Hashtable<>();
//Adding parameters
params.put("name", name);
params.put("phone", phone);
params.put("email", email);
params.put("address", address);
//returning parameters
return params;
}
};
new MySingleton(first_run.this).addToRequestQueue(stringRequest);
}
虽然这是我的php脚本:
<?php
extract($_POST);
if(isset($name)){
$resp='';
include 'config.php';
$sql = "INSERT INTO users (id,name,phone,email,address)
VALUES ('','".$name."', '".$phone."', '".$email."','".$address."')";
if ($conn->query($sql) === TRUE) {
$resp="success";
echo($resp);
$sql = "INSERT INTO log (id,response) Values('','".$resp."')";
$conn->query($sql);
}else {
$resp= "Error: " . $sql . "<br>" . $conn->error;
$conn->query($sql);
echo($resp);
}}else{
echo "Empty data";
}
?>