第51行文件意外结束时没有结束

时间:2014-04-15 13:29:26

标签: php

我有一个函数文件,当我向它添加一个函数时,无论在哪里,它都表示第51行的文件意外结束。

这是我的代码。

<?php

function newcat() {

    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);



    if (!isset($_SESSION['user_id'])) {

    echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';

    exit();

  }

  else {

    echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.</p>');

  }







  // Connect to the database





  if (isset($_POST['submit'])) {

    // Grab the profile data from the POST

    $catt = mysqli_real_escape_string($dbc, strip_tags( trim($_POST['catt']))); $desc = mysqli_real_escape_string($dbc, strip_tags( trim($_POST['desc'])));



    // Update the post data in the database

      if (!empty($catt)) {

      strip_tags($post1);

    $query = "INSERT INTO categories (`name`, `desc`) VALUES ('$catt', '$desc')";

        mysqli_query($dbc, $query);



        // Confirm success with the user

        echo '<p>Your category has been successfully added. Would you like to go back to the <a href="acp.php">Admin Panel</a>?</p>';

        echo $catt;

        mysqli_close($dbc);

        exit();

      }

      else {

        echo '<p class="error">You must enter information into all of the fields.</p>';

      }

  } // End of check for form submission

if(!verify("O")){exit();}

 echo'<form enctype="multipart/form-data" method="post" action="acp.php?action=vc">

    <fieldset>

      <legend>Create Category:</legend>

        <label type="hidden" for="catt">Category name:</label><br />

        <input type="text" name="catt"><br /><br />             <label type="hidden" for="desc">Description</label><br />               <textarea rows="4"  name="desc" id="desc" cols="100"></textarea>

    </fieldset>

    <input type="submit" value="Save Category" name="submit" />     

  </form>';


    echo '<table class"admin" border=1>';

  echo '<tr><th>Categories</th></tr>';

    $query = "SELECT * FROM categories ORDER BY cat_id ASC";

  $data = mysqli_query($dbc, $query);

  $gender = $row['gender'];

  while ($row = mysqli_fetch_array($data)) {

    echo '<tr>';

  echo '<td>'.$row['name'].'</td></tr>';

  }

          mysqli_close($dbc);



  echo'</table>';

   echo'</div>';
}

function verify($permissionName){

  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 

    $query = "SELECT permissions FROM user WHERE user_id = '" . $_SESSION['user_id'] . "'";

  $data = mysqli_query($dbc, $query);

$row = mysqli_fetch_array($data);

  if($row['permissions'] === $permissionName){

    return true;

  } else {

    return false;

  }

}





function group($groupName){

  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 

    $query = "SELECT usergroup FROM user WHERE user_id = '" . $_SESSION['user_id'] . "'";

  $data = mysqli_query($dbc, $query);

$row = mysqli_fetch_array($data);

  if($row['usergroup'] === $groupName){

    return true;

  } else {

    return false;

  }

}



function gperms($groupPerm, $user) {

  $query = "SELECT * FROM groups WHERE group_id = $group";

  $data = mysqli_query($dbc, $query);

$row = mysqli_fetch_array($data);

$groupname = $row['groupname'];

$users = explode(",", $row['username']);

foreach($users as $k => $member){

  list($username, $rank) = explode(":", $member);

}



    $query = "SELECT usergroup FROM user WHERE user_id = '" . $_SESSION['user_id'] . "'";

  $data = mysqli_query($dbc, $query);

$row = mysqli_fetch_array($data);

  if(($row['username'] === $user) && ($rank === $groupPerm)){

    return true;

    } else {

    return false;

    }

    }



?>

我需要知道造成这种情况的原因,因为在第51行它显示mysqli_query($dbc, $query);并且不应该结束文件。

此外,我可以在另一个文件中使用它,但它可以工作,但不在此文件中。

2 个答案:

答案 0 :(得分:0)

也许你有编码问题。也许您的服务器由Linux驱动,但您使用Windows(反之亦然),而您的文本编辑器没有考虑Linux和Windows下编码的差异。

答案 1 :(得分:0)

未检测到语法错误。

对我而言,这需要在黑暗中进行拍摄:尝试再次将文件上传到服务器。

可能由于网络故障,您的文件只上传了一半,这会导致文件意外结束&#34;错误。