安卓端代码: public void inserthttp(String jd,String wd,Drawable er)
{
/*声明网址字符串*/
String uriAPI = "http://59.37.191.158:8090/guestbook.php";
/*建立HTTP Post联机*/
HttpPost httpRequest = new HttpPost(uriAPI);
/*
* Post运作传送变量必须用NameValuePair[]数组储存
*/
List <NameValuePair> params = new ArrayList <NameValuePair>();
params.add(new BasicNameValuePair("j", jd));
params.add(new BasicNameValuePair("w", wd));
try
{
/*发出HTTP request*/
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
/*取得HTTP response*/
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
/*若状态码为200 ok*/
if(httpResponse.getStatusLine().getStatusCode() == 200)
{
/*取出响应字符串*/
String strResult = EntityUtils.toString(httpResponse.getEntity(), "GBK");
jarry = new JSONArray(strResult);
for(int i=0;i<jarry.length();i++){
try {
mMapView.getOverlays().add(new OverItemT(er, this,jarry.getJSONObject(i).getString("j"),jarry.getJSONObject(i).getString("w"),jarry.getJSONObject(i).getString("gjxname"),jarry.getJSONObject(i).getString("Content")));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else
{
}
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
}在服务器端用php接收参数并查询和插入,但是只执行了查询没执行插入[<?php
$j=$_POST['j'];
$jMax=$j+0.002;
$jMin=$j-0.002;
$w=$_POST['w'];
$wMax=$w+0.002;
$wMin=$w-0.002;
include_once("db/conn.php");
$query="SELECT * FROM gjx where j<".$jMax." and j>".$jMin." and w<".$wMax." and w>".$wMin." order by id asc";
//$query="SELECT * FROM gjx order by id asc";
$result=mysql_query($query);
$query1="insert into guestbook (gjxname,Content) VALUES('".$j."','".$j."')";
mysql_query($query1);
while($r=mysql_fetch_array($result)){
?>
{"gjxname":"<?=$r["gjxname"]?>","j":"<?=$r["j"]?>","w":"<?=$r["w"]?>","Content":"<?=$r["Content"]?>"},
<?php
}
?>]不知道什么原因啊,把$query1="insert into guestbook (gjxname,Content) VALUES('".$j."','".$j."')";改成
$query1="insert into guestbook (gjxname,Content) VALUES('你好','你好')";一样不插入啊
{
/*声明网址字符串*/
String uriAPI = "http://59.37.191.158:8090/guestbook.php";
/*建立HTTP Post联机*/
HttpPost httpRequest = new HttpPost(uriAPI);
/*
* Post运作传送变量必须用NameValuePair[]数组储存
*/
List <NameValuePair> params = new ArrayList <NameValuePair>();
params.add(new BasicNameValuePair("j", jd));
params.add(new BasicNameValuePair("w", wd));
try
{
/*发出HTTP request*/
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
/*取得HTTP response*/
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
/*若状态码为200 ok*/
if(httpResponse.getStatusLine().getStatusCode() == 200)
{
/*取出响应字符串*/
String strResult = EntityUtils.toString(httpResponse.getEntity(), "GBK");
jarry = new JSONArray(strResult);
for(int i=0;i<jarry.length();i++){
try {
mMapView.getOverlays().add(new OverItemT(er, this,jarry.getJSONObject(i).getString("j"),jarry.getJSONObject(i).getString("w"),jarry.getJSONObject(i).getString("gjxname"),jarry.getJSONObject(i).getString("Content")));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else
{
}
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
}在服务器端用php接收参数并查询和插入,但是只执行了查询没执行插入[<?php
$j=$_POST['j'];
$jMax=$j+0.002;
$jMin=$j-0.002;
$w=$_POST['w'];
$wMax=$w+0.002;
$wMin=$w-0.002;
include_once("db/conn.php");
$query="SELECT * FROM gjx where j<".$jMax." and j>".$jMin." and w<".$wMax." and w>".$wMin." order by id asc";
//$query="SELECT * FROM gjx order by id asc";
$result=mysql_query($query);
$query1="insert into guestbook (gjxname,Content) VALUES('".$j."','".$j."')";
mysql_query($query1);
while($r=mysql_fetch_array($result)){
?>
{"gjxname":"<?=$r["gjxname"]?>","j":"<?=$r["j"]?>","w":"<?=$r["w"]?>","Content":"<?=$r["Content"]?>"},
<?php
}
?>]不知道什么原因啊,把$query1="insert into guestbook (gjxname,Content) VALUES('".$j."','".$j."')";改成
$query1="insert into guestbook (gjxname,Content) VALUES('你好','你好')";一样不插入啊
解决方案 »
- android 开发用什么手机好 晒晒你们的手机
- android填色小游戏
- 求一个Android Activity跳转的例子,在线等
- 求助:使用NDK编程,fread读取文件,返回值总是0?
- 散分,终于完成可以在Android和PC上互通的UDP可靠传输协议
- 静默安装出现NameNotFoundException错误
- Android 如何调用系统默认的应用程序列表界面,如下图
- 问相机在一个Activity预览按回退键后再次回来不显示问题
- 求助,怎么监控apk安装过程
- 新安装了电脑,android手机或其它android设备接电脑时,adb shell 用不了.
- div的overflow属性在安卓2.3浏览器里面无效,怎么解决?
- 全部分就剩30分了 请教一个问题
$query1="insert into guestbook (gjxname,Content) VALUES('".$j."','".$j."')";
$result =mysql_query($query1);
再判断一下$result值是否为true.
能插入数字类的字符串,不能插入中文