如何从php发送和捕获数据到Android设备?

时间:2012-06-27 10:16:36

标签: php android json

我为我的网站制作了以下代码,效果非常好,但我现在正在研究Android版本,并尝试从php脚本中捕获不能正常运行的resposnse

网站代码

<?php


include('config.php');
$link =mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$sql="SELECT * FROM logintbl WHERE stu_email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

session_start();
$_SESSION['username'] = $myusername;
$_SESSION['password'] = $mypassword;

header("location:login_success.php");
}
else {
header('Location: http://www.xxxxxxx.com/pabrowser/index.php?succmsg1=INVALID.RETRY');
}
?>

代码更改为与Android设备一起使用

<?php
$link = mysql_connect(xxxxxxxx);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("brainoidultrafb", $link);


$sql="SELECT * FROM logintbl WHERE stu_email='".$_REQUEST['id']."' and password='".$_REQUEST['pass']."'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$output[]=$count;
print(json_encode($output));

mysql_close();
?>

输出应该是0或1,这将允许设备登录。

0 个答案:

没有答案