我試圖發送一些值到服務器中的PHP文件使用Http post ...它只存儲在我的MySQL數據庫的字段中的空值.. ..please幫我...發表一些值到PHP並存儲在數據庫中使用HTTP,只存儲空值
我的Android代碼:
private void sendValues()
{
List<NameValuePair> data= new ArrayList<NameValuePair>(2);
data.add(new BasicNameValuePair("number", "123456789"));
data.add(new BasicNameValuePair("msg", "haiRam"));
try {
HttpClient httpclient=new DefaultHttpClient();
HttpPost httppost=new HttpPost("http://www.mywebsite.com/fasttrack/HttpTest.php");
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse rs=httpclient.execute(httppost);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我的PHP代碼:
<?php
// Gets data from URL parameters
$mobile=$_GET['number'];
$message = $_GET['msg'];
echo $message;
echo $mobile;
$connection=mysql_connect ("mysql", "user", "pass");
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db("gps", $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Insert new row with user data
$query = sprintf("INSERT INTO Http" .
" (mobile,mess) " .
" VALUES ('%s', '%s');",
mysql_real_escape_string($mobile),
mysql_real_escape_string($message));
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
?>