【发布时间】:2015-08-14 20:00:09
【问题描述】:
我正在开发一个应用程序,我在其中传递凭据,然后通过 post 方法传递它。在这个页面中,我想访问登录页面中填写的 regno 和 pass 值。但我没有得到价值观。我尝试将值回显为 $data->regno,但我得到了 Null 值。请告诉我我做错了什么。
<?php
ini_set('display_errors', '0');
error_reporting(0);
require_once("include/db.php");
class mysendclass{
public $name="Invalid";
public $priority=-1;
public $url="";
}
class myrecclass{
public $regno="";
public $pass="";
}
$e=new mysendclass();
$g=new myrecclass();
if(isset($_POST))
{
$data=json_decode(file_get_contents('php://input'));
foreach ($data AS $key => $value) $g->{$key} = $value;
$query = "SELECT priority, name, url FROM users WHERE regno='{$data->regno}' AND pass='{$data->pass}' LIMIT 1";
echo ($query);
$res = mysql_query($query, $conn) or die(mysql_error());
$found = mysql_fetch_array($res);
echo ($found);
if($found)
{
$e->name=$found['name'];
$e->priority=$found['priority'];
$e->url=$found['url'];//url
}
echo json_encode($e);
}
?>
当我发布凭据时,尽管从数据库中发布了正确的凭据,但我还是收到了这个:
{"name":"Invalid","priority":-1,"url":""}
【问题讨论】:
标签: php arrays json post urldecode