首页 / 操作系统 / Linux / Android与PHP服务器交互实例源码
实现的功能就是远程注册登录后,跳转到首页,首页显示欢迎信息,并把服务器从数据库取回的数据以json格式返回,并显示在listview上,登录用户的代码是参考一位坛友的本地注册登录的实例。服务器端:server.php<?php
include("dbconfig.php");
$address = $_POST["address"];
$longitude = $_POST["longitude"];
$latitude = $_POST["latitude"];
if(empty($address) or empty($longitude) or empty($latitude)){
die("You have to fill all the fields!");
}
$conn = mysql_connect($server,$username,$password);
if(!$conn){
die("connection failed:".mysql_error());
} mysql_select_db($dbName,$conn); $query = "insert into ".$tableName." values(NULL,"".$address."",".$longitude.",".$latitude.","".date("Y-m-d H:i:s",time())."");";
$result = mysql_query($query,$conn);
if(!$result){
die("mysql error:".mysql_error());
} echo "add information to database sucessfullly!";
?>