Php 无法从Android在Mysql中插入数据
我正在尝试连接Android、PHP和MySql。 为此,使用Android作为前端,我试图将数据插入MySql数据库。 我使用logcat输出在适当的位置显示信息。 响应显示在logcat中,但MySql中没有数据。 请帮帮我 这是我的密码:Php 无法从Android在Mysql中插入数据,php,android,mysql,Php,Android,Mysql,我正在尝试连接Android、PHP和MySql。 为此,使用Android作为前端,我试图将数据插入MySql数据库。 我使用logcat输出在适当的位置显示信息。 响应显示在logcat中,但MySql中没有数据。 请帮帮我 这是我的密码: public JSONObject getJsonData(String url_create_product, List<NameValuePair> parameters) { try { Log.e(
public JSONObject getJsonData(String url_create_product, List<NameValuePair> parameters)
{
try
{
Log.e("url is:"," "+url_create_product.toString());
DefaultHttpClient httpClient= new DefaultHttpClient();
Log.e("httpClient is:"," "+httpClient.toString());
HttpPost httpPost=new HttpPost(url_create_product);
Log.e("httpPost is:"," "+httpPost.toString());
httpPost.setEntity(new UrlEncodedFormEntity(parameters));
Log.e("encoded parameters are: "," "+parameters.toString());
try
{
httpResponse=httpClient.execute(httpPost);
Log.e("httpResponse is:"," "+httpResponse.toString());
}
catch (Exception e)
{
e.printStackTrace();
}
int statusCode=httpResponse.getStatusLine().getStatusCode();
if (statusCode==200)
{
Log.e("statusCode is:","200");
HttpEntity httpEntity=httpResponse.getEntity();
inputStream=httpEntity.getContent();
Log.e("inputStream is:"," "+inputStream.toString());
BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
inputStream.close();
json = sb.toString();
Log.e("json is:"," "+json.toString());
jsonObject=new JSONObject(json);
Log.e("jsonObject is:"," "+jsonObject.toString());
}
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonObject;
}
publicjsonobjectgetjsondata(字符串url\u创建\u产品,列表参数)
{
尝试
{
Log.e(“url为:”,“+url\u create\u product.toString());
DefaultHttpClient httpClient=新的DefaultHttpClient();
Log.e(“httpClient是:”,“+httpClient.toString());
HttpPost HttpPost=新的HttpPost(url\u创建\u产品);
Log.e(“httpPost是:,”“+httpPost.toString());
setEntity(新的UrlEncodedFormEntity(参数));
Log.e(“编码参数为:”、“”+parameters.toString());
尝试
{
httpResponse=httpClient.execute(httpPost);
Log.e(“httpResponse是:”,“+httpResponse.toString());
}
捕获(例外e)
{
e、 printStackTrace();
}
int statusCode=httpResponse.getStatusLine().getStatusCode();
如果(状态代码==200)
{
Log.e(“状态代码为:”,“200”);
HttpEntity HttpEntity=httpResponse.getEntity();
inputStream=httpEntity.getContent();
Log.e(“inputStream为:”,“+inputStream.toString());
BufferedReader reader=新的BufferedReader(新的InputStreamReader(
输入流,“iso-8859-1”),8);
StringBuilder sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null)
{
sb.追加(第+行“\n”);
}
inputStream.close();
json=sb.toString();
e(“json是:”,“+json.toString());
jsonObject=新的jsonObject(json);
e(“jsonObject是:”,“+jsonObject.toString());
}
}
捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}捕获(JSONException e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回jsonObject;
}
如果收到响应,请确保服务器端php脚本是否正确插入。如果从web浏览器进行测试,php服务器脚本是否返回正确的响应?发布php脚本并将收到的响应发布到android客户端。