我对 Php 完全陌生,我正在尝试将 json 数据从 php 发送到 android。我在 php 中有以下代码从数据库中读取值:
<?php
$con=mysql_connect("localhost","root","");
if(! $con)
{
die('Connection Failed'.mysql_error());
}
mysql_select_db("registration",$con);
$name="Adam";//$_POST["name"];
$password="charles";//$_POST["password"];
$sql="SELECT * FROM users WHERE name='$name'and password='$password'";
$result=mysql_query($sql, $con);
while($row = mysqli_fetch_array($result))
{
$details= array(
'name' => $row['name'],
'password' => $row['password'],
);
array_push($json, $bus);
}
$jsonstring = json_encode($json);
echo $jsonstring;
mysql_close();
?>
我期望输出是这样的:
[{"name":"Adam","age":"25","surname":"charles"}]
如果我没记错 JSON 数据。但这给了我错误:
mysqli_fetch_array() expects parameter 1 to be mysqli_result, resource given in...
并且
Undefined variable: json in...
有人可以告诉我可能是什么错误