将MYSQL数据库连接到Android DeviceHP的PHP脚本错误
我的PHP脚本连接有问题,它不断返回“Oops!Its this.”-如果无法插入mySQL数据库,这就是我的错误消息将MYSQL数据库连接到Android DeviceHP的PHP脚本错误,php,android,mysql,database,Php,Android,Mysql,Database,我的PHP脚本连接有问题,它不断返回“Oops!Its this.”-如果无法插入mySQL数据库,这就是我的错误消息 ///PHP SCRIPT <?php $con = mysqli_connect("postgrad.nmmu.ac.za", "Christian", "Christian123", "drmdb"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_co
///PHP SCRIPT
<?php
$con = mysqli_connect("postgrad.nmmu.ac.za", "Christian", "Christian123", "drmdb");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// array for JSON response
$response = array();
$PointerID = $_POST['PointerID'];
$ActivityID = $_POST['ActivityID'];
$StartX = $_POST['StartX'];
$EndX = $_POST['EndX'];
$StartY = $_POST['StartY'];
$EndY = $_POST['EndY'];
$Content = $_POST['Content'];
$Head = $_POST['Head'];
$NodeID = $_POST['NodeID'];
$Step = $_POST['Step'];
$result = mysqli_query(
$con,
"INSERT INTO pointersequence(PointerID, ActivityID, StartX, StartY, EndX, EndY, Content, Head, NodeID, Step) VALUES('$PointerID','$ActivityID', '$StartX', '$StartY', '$EndX', '$Content', '$Head', '$NodeID', '$Step')"
);
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Person successfully created hahaha.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! Its this one.";
// echoing JSON response
echo json_encode($response);
}
mysql_close($con);
?>
OUTPUT: Oops! Its this one.
//Method in Android to Insert
private void UploadPointerSequence() {
int num11 = 1;
final String URL12 = "http://drm.csdev.nmmu.ac.za/UploadPointerSequence.php";
for (int x = 0; x <= PointerSequence.size() - 1; x++) {
List<NameValuePair> param12 = new ArrayList<NameValuePair>();
param12.add(new BasicNameValuePair("PointerID", String
.valueOf(num11)));
num11++;
param12.add(new BasicNameValuePair("ActivityID", String
.valueOf(PointerSequence.get(x).getActivityID())));
param12.add(new BasicNameValuePair("StartX", String
.valueOf(PointerSequence.get(x).getStartX())));
param12.add(new BasicNameValuePair("StartY", String
.valueOf(PointerSequence.get(x).getStartY())));
param12.add(new BasicNameValuePair("EndX", String
.valueOf(PointerSequence.get(x).getEndX())));
param12.add(new BasicNameValuePair("EndY", String
.valueOf(PointerSequence.get(x).getEndY())));
param12.add(new BasicNameValuePair("Content", PointerSequence
.get(x).getContent()));
param12.add(new BasicNameValuePair("Head", String
.valueOf(PointerSequence.get(x).isHead())));
param12.add(new BasicNameValuePair("NodeID", String
.valueOf(PointerSequence.get(x).getNodeID())));
param12.add(new BasicNameValuePair("Step", String
.valueOf(PointerSequence.get(x).getStep())));
JSONObject json = jsonParser.makeHttpRequest(URL12, "POST",
param12);
}
}
>JSON CLASS:
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
// function get json from url
// by making HTTP POST or GET mehtod
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
// Making HTTP request
try {
// check for request method
if(method == "POST"){
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}else if(method == "GET"){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
Thanks in Advance!
///PHP脚本
您将MySQL API与MySQL\u close($con)混合使用代码>使用mysqli\u关闭($con)代码>-这两个API不会混合使用。在>//JSON响应数组
和>//JSON响应数组
中也有一些零散的>
-如果它们是代码的一部分,请删除它们。你的代码注释很混乱。对不起,我的注释有点仓促…很抱歉!我已经从mysql_close($con)进行了更改;至mysqli_close($con);但是,在打开