PHP登录脚本json错误
我的php脚本中有一个错误,我正在postman中执行该脚本,以便在android studio中使用。响应部分没有执行该脚本,并给出一个错误 请帮帮我PHP登录脚本json错误,php,android,login,Php,Android,Login,我的php脚本中有一个错误,我正在postman中执行该脚本,以便在android studio中使用。响应部分没有执行该脚本,并给出一个错误 请帮帮我 <?php $con = mysqli_connect("", "", "", ""); $username = $_POST["username"]; $password = $_POST["password"]; $query = "SELECT * FROM user_info WHERE u
<?php
$con = mysqli_connect("", "", "", "");
$username = $_POST["username"];
$password = $_POST["password"];
$query = "SELECT * FROM user_info WHERE username = '$username' AND password ='$password'";
$result=mysqli_query($con,$query);
$response=array();
if(mysqli_num_rows($result)>=1)
{
$data=mysqli_stmt_fetch($result)
$response['success'] = 'true';
$response["name"] = $data['name'];
$response["age"] = $data['age'];
$response["username"] = $data['username'];
$response["password"] = $data['password'];
}
if(mysqli_num_rows($result)<1){
$response["success"] = 'false';
}
echo json_encode($response);
?>
您缺少分号;在这一行的末尾:
$data=mysqli_stmt_fetch($result)
^
在SQL查询中将php变量与字符串连接时犯了一个小错误。请把鳍放在正确的下面
<?php
$con = mysqli_connect("", "", "", "");
$username = $_POST["username"];
$password = $_POST["password"];
$query = "SELECT * FROM user_info WHERE username = '".$username."' AND password ='".$password."'";
$result=mysqli_query($con,$query);
$response=array();
if(mysqli_num_rows($result)>=1)
{
$data=mysqli_stmt_fetch($result);
$response['success'] = 'true';
$response["name"] = $data['name'];
$response["age"] = $data['age'];
$response["username"] = $data['username'];
$response["password"] = $data['password'];
}
if(mysqli_num_rows($result)<1){
$response["success"] = 'false';
}
echo json_encode($response);
?>
没有按数据命名的数组。因此,$data['name']不可用
if(mysqli_num_rows($result)>=1)
{
$data=mysqli_stmt_fetch($result);//semi colon was missing
$response['success'] = 'true';
$response["name"] = $data['name'];//unable to find $data array
$response["age"] = $data['age'];//unable to find $data array
$response["username"] = $data['username'];//unable to find $data array
$response["password"] = $data['password'];//unable to find $data array
}
我们不会为你做家庭作业。23号线在哪里,你试图解决什么问题等等……哎呀!您正在使用纯文本密码!!!!PHP提供并请使用它们。如果您在这一行中使用的是5.5$data=mysqli\u stmt\u fetch$result之前的PHP版本,那么这里有一些;。它应该$data=mysqli\u stmt\u fetch$result;
if(mysqli_num_rows($result)>=1)
{
$data=mysqli_stmt_fetch($result);//semi colon was missing
$response['success'] = 'true';
$response["name"] = $data['name'];//unable to find $data array
$response["age"] = $data['age'];//unable to find $data array
$response["username"] = $data['username'];//unable to find $data array
$response["password"] = $data['password'];//unable to find $data array
}