在Android应用程序中,我使用Php代码将数据插入到SQL数据库中 当我将一条记录插入数据库时,它会插入两条记录。这是
PHP:
<?php
$mysql_host = "localhost";
$mysql_database = "...";
$mysql_user = "...";
$mysql_password = "...";
$con = mysql_connect($mysql_host, $mysql_user,$mysql_password,$mysql_database) || die("Error DB Connect");
$selectedDb = mysql_select_db($mysql_database)|| die("Error in opening DB");
$points = $_POST["points"];
$user = $_POST["user"];
$sql = "INSERT INTO `cusTrans`( `CID`, `Point`, `Date`, `time`,`Description`)
VALUES ($user,$points,CURRENT_DATE,CURRENT_TIME,'Claim Point')";
if (mysql_query($sql)) {
echo "OK";
} else {
echo "Fault".mysql_error();
}
?>
机器人:
httpclientCD = new DefaultHttpClient();
httppostCD = new HttpPost("http://.../ClaimRecord.php");
nameValuePairsCD = new ArrayList<NameValuePair>(2);
nameValuePairsCD.add(new BasicNameValuePair("user", cus_id1));
nameValuePairsCD.add(new BasicNameValuePair("points", "1"));
httppostCD.setEntity(new UrlEncodedFormEntity(nameValuePairsCD));
// Execute HTTP Post Request
responseCD = httpclientCD.execute(httppostCD);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response1 = httpclientCD.execute(httppostCD, responseHandler);
System.out.println("Response CusUpdatePOint : "+id+"--" + response1);
答案 0 :(得分:1)
你可以尝试在android部分中注释以ResponseCD开头的行吗? 对不起,简短的回答,但我在我的手机上。