这是我的insert.php脚本
<?php
$name=$_POST['Name'] ?? '' ;
$address=$_POST['Address'] ?? '' ;
include("db_config.php");
$result = mysqli_query($con,"INSERT INTO `Firm`(`ID`,`NAME`,`ADDRESS`) VALUES ('','$name','$address')");
$response = array();
if($result){
$response['success']=1;
$response['message']="Record Inserted Successfully-".$result."--";
}
else {
$response['success']=0;
$response['message']="Insertion Failure-".$result."--";
}
echo json_encode($response);
?>
这是响应代码
request = new StringRequest(Request.Method.POST, Utils.INSERT_FIRM, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
// Log.i("R","Response is "+s);
try {
JSONObject jsonObject = new JSONObject(s);
int success = jsonObject.getInt("success");
String message = jsonObject.getString("message");
Toast.makeText(Add_Firm.this,""+message+":"+ success,Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(Add_Firm.this, "Some Error"+e.toString(), Toast.LENGTH_SHORT).show();
Log.i("Error"," "+e.toString());
}
}
我使用php脚本将android连接到数据库 当我单击应用程序中的提交按钮时 虽然插入发生在数据库但是 我一直在android
中得到这个异常org.json.JSONException: Value Connection of type java.lang.String cannot be converted to JSONObject
问题是什么?