下面是PHP服務器的代碼:試圖將數據發佈到PHP,但數據沒有被正確讀取
?php
//from the online tutorial:
$usr = "bikemap";
$pwd = "pedalhard";
$db = "test";
$host = "localhost";
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
$userID = $_POST['userID'];
$date = $_POST['date'];
$time = $_POST['time'];
$lat = $_POST['lat'];
$long = $_POST['longi'];
$alt = $_POST['alt'];
mysql_select_db("test");
mysql_query("INSERT INTO gpsdata (userID, date, time, lat, longi, alt) VALUES ('$userID', '$date', '$time', '$lat','$longi','$alt') ") or die(mysql_error());
/*$SQL = " INSERT INTO gpsdata ";
$SQL = $SQL . " (userID, date, time, lat, longi, alt) VALUES ";
$SQL = $SQL . " ('$userID', '$date', '$time', '$lat','$longi','$alt') ";
$result = mysql_query("$SQL");
if (!$result) {
echo("ERROR: " . mysql_error() . "\n$SQL\n"); } */
//echo ("New Link Added\n");
mysql_close($cid);
?>
從我的Android應用程序發送的數據:
[userID=Loren, date=today, time=now, lat=bit 1, longi=bit 2, alt=bit 3]
出於某種原因,我PHP不讀取從Android應用程序(如上所示)發送的數據,但如果我從本地網頁發送相同的數據發佈的數據解析應該。
public static void sendAccelerationData(String userIDArg, String dateArg, String timeArg,
String timeStamp, String lat, String longi, String alt)
{
//Add data to be send.
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
nameValuePairs.add(new BasicNameValuePair("userID", userIDArg));
nameValuePairs.add(new BasicNameValuePair("date",dateArg));
nameValuePairs.add(new BasicNameValuePair("time",timeArg));
//nameValuePairs.add(new BasicNameValuePair("timeStamp",timeStamp));
nameValuePairs.add(new BasicNameValuePair("lat",lat));
nameValuePairs.add(new BasicNameValuePair("longi",longi));
nameValuePairs.add(new BasicNameValuePair("alt",alt));
//this.sendData(nameValuePairs);
try
{
TextLog.addLogStuff("SERV Trying to connect to Server");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://myserver.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.i("ServerConn", response.getStatusLine().toString());
TextLog.addLogStuff("SERV PostData: " +response.getStatusLine().toString());
//Could do something better with response.
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
TextLog.addLogStuff("SERV Connection error: " +e.toString());
}
}
把那個教程拿回來,並將其折磨到死亡。它留給你敞開SQL注入攻擊 –
cough..SQL注射!.. ahem..cough –
它們是什麼想說的是去使用PDO ......認真壽傢伙..一個教程,你不關心sql注入 – Zak