解析错误:语法错误,意外' {'

时间:2016-03-15 08:25:33

标签: php

我正在使用Android应用程序......我试图插入在线服务器但我收到错误说"解析错误:语法错误,意外&# 39; {'第44行(if(isempty)) 我只想查看哪些字段是空的....... 这是代码

<?php
$con=mysqli_connect("mysql4.000webhost.com","a9023721_Recomd","123password","a9023721_Logs") or die(mysql_error());
$db=mysqli_select_db($con,"a9023721_Logs");
$response=array();

if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['User'])&&isset($_POST['SongId'])&&isset($_POST['SongTitle'])&&isset($_POST['AlbumId'])&&isset($_POST['Album'])&&isset($_POST['TimeStamp']))
{
$User = $_POST['User'];
$SongId = $_POST['SongId'];
$SongTitle=$_POST['SongTitle'];
$AlbumId=$_POST['AlbumId'];
$Album=$_POST['Album'];
$TimeStamp=$_POST['TimeStamp'];
$result = mysqli_query($con,"INSERT INTO LogTable (User,SongId,SongTitle,AlbumId,Album,TimeStamp) VALUES ('$User', '$SongId', '$SongTitle', '$AlbumId', '$Album', '$TimeStamp')");
$row = mysqli_fetch_array($result);
$data = $row[0];

if($data){
    echo $data;
}
if (mysql_affected_rows() > 0) {
    // successfully updated
    $response["success"] = 1;
    $response["message"] = "Product successfully deleted";

    // echoing JSON response
    echo json_encode($response);
} else {
    // no product found
    $response["success"] = 0;
    $response["message"] = "No product found";

    // echo no users JSON
    echo json_encode($response);
}
} 
 else {
// required field is missing
$response["success"] = 0;
if (empty($_POST['User']) {
$response["message"] = "Required field(s) User is missing";
} elseif (empty($_POST['SongId']) {
$response["message"] = "Required field(s) ID is missing";
} elseif (empty($_POST['SongTitle']) {
$response["message"] = "Required field(s) SongTitle is missing";
}
// echoing JSON response
echo json_encode($response);
}

mysqli_close($con);
?>

2 个答案:

答案 0 :(得分:2)

显示错误,因为您没有结束空()函数:

if (empty($_POST['User']))
                         ^---- missing bracket here!

以下是您编辑的部分代码:

// required field is missing
$response["success"] = 0;
if (empty($_POST['User'])) {
$response["message"] = "Required field(s) User is missing";
} elseif (empty($_POST['SongId'])) {
$response["message"] = "Required field(s) ID is missing";
} elseif (empty($_POST['SongTitle'])) {
$response["message"] = "Required field(s) SongTitle is missing";
}

答案 1 :(得分:2)

使用以下内容更改else广告代码。

你错过了关闭每个if条件的empty

else {
// required field is missing
$response["success"] = 0;
if (empty($_POST['User'])) {
$response["message"] = "Required field(s) User is missing";
} elseif (empty($_POST['SongId'])) {
$response["message"] = "Required field(s) ID is missing";
} elseif (empty($_POST['SongTitle'])) {
$response["message"] = "Required field(s) SongTitle is missing";
}