我有一个错误在我的PHP脚本,我在邮差执行将在android工作室使用。响应部分没有执行它给出了一个错误
<b>Parse error</b>: syntax error, unexpected '$response' (T_VARIABLE) in
<b>/home/u259428939/public_html/Login.php</b> on line
<b>23</b>
<br />
请帮帮我。
<?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
命名的数组。因此$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
}