我有代码,我正在尝试提交到数据库,并且代码在模拟器上正常工作但是一旦我移动到实际设备,相同的代码将不再起作用。我认为它与我的php中的time()函数有关(我不知道它可能是什么)但是我错过了一些明显的东西吗?在物理Android设备上的这个代码总是抛出“哎呀!发生错误。”但是在我的电脑上我的模拟器上工作得很好。我已经检查过以确保我上传了该项目的新副本。
<?php
/*
* Following code will create a new product row
* All product details are read from HTTP Post Request
*/
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['assemblyLotNumber']) && isset($_POST['assemblyID']) && isset($_POST['assemblerID']) && isset($_POST['quantity'])) {
$assemblyLotNumber = $_POST['assemblyLotNumber'];
$assemblyID = $_POST['assemblyID'];
$assemblerID = $_POST['assemblerID'];
$quantity = $_POST['quantity'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
$time = time();
// connecting to db
$db = new DB_CONNECT();
// mysql inserting a new row
$result = mysql_query("INSERT INTO assemblylot (assemblyLotNumber, assemblyID, assemblerID, date, isPremade, quantity) VALUES('$assemblyLotNumber', '$assemblyID', '$assemblerID', $time, 1, '$quantity')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "premade assembly successfully created.";
$response["date"] = $time;
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
$response["date"] = $time;
// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
这是我在代码中调用的地方
public void submitAssemblyLot(Assembly a) {
List<NameValuePair> assemblyParam = new ArrayList<NameValuePair>();
assemblyParam.add(new BasicNameValuePair("assemblyLotNumber", Integer.toString(a.getAssemblyLotNumber())));
assemblyParam.add(new BasicNameValuePair("assemblyID", Integer.toString(a.getAssemblyID())));
assemblyParam.add(new BasicNameValuePair("assemblerID", Integer.toString(a.getAssemblerID())));
try {
JSONObject json = jsonParser.makeHttpRequest(
url_submit_assembly_lot, "POST", assemblyParam);
String message = json.getString("message");
String date1 = json.getString("time");
Log.d("submitAssemblyLot", message);
Log.d("submitAssemblyLot", date1);
} catch (JSONException e) {
e.printStackTrace();
}
}