如何检测php中$ end错误的确切位置

时间:2010-05-13 06:32:03

标签: php

我在php中遇到此错误的问题:

 Parse error: syntax error, unexpected $end in J:\Server\xampplite\htdocs\exp\printact.php  on line 172

可能缺少支架或其他东西。是否有任何工具可以帮我确定错误的确切位置?

编辑: 这是代码,它是一团糟:))

<link rel="stylesheet" href="print.css" type="text/css" media="print" />

<font size="3"><center><b>XD627 INFORMATION MANAGEMENT SYSTEM</b></center></font>

<br />
<br />

<div id="max">






    <?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("school", $con);
?> 



<?php 

$ShowImage= ( $_POST['pic'] == 'pix');


$ShowFirstName = ( $_POST['fname'] == 'firstname');

$ShowLastName = ( $_POST['lname'] == 'lastname');

$ShowMidName = (  $_POST['mname'] == 'midname');

$ShowAddress = (  $_POST['ad'] == 'address');

$ShowGender = ( $_POST['gender'] == 'gen');


$ShowReligion = (  $_POST['rel'] == 'religion');

$ShowBday = (   $_POST['bday'] == 'birthday');

$ShowContact = (   $_POST['contact'] == 'contactnum');

$ShowMother = (   $_POST['mother'] == 'ma');

$ShowMotherOcc = (  $_POST['mother_occ'] == 'ma_occ');

$ShowFather = (   $_POST['father'] == 'pa');

$ShowFather_Occ = (  $_POST['father_occ'] == 'pa_occ');

$ShowParentAddress = (  $_POST['parent_add'] == 'pad');


$ShowParentContact = (  $_POST['parent_contact'] == 'pcon');

$id =  mysql_real_escape_string($_POST['idnum']); 
$result2 = mysql_query("SELECT * FROM student WHERE IDNO='$id'"); 
$result3 = mysql_query("SELECT * FROM mother WHERE IDNO='$id'");
$result4 = mysql_query("SELECT * FROM father WHERE IDNO='$id'");
$result5 = mysql_query("SELECT * FROM parents WHERE IDNO='$id'");
?>

<?php while($row = mysql_fetch_array($result2)) 
{ 
?>

<font size="2"><b><u>Student Information</br></b></u></font><br>

<?php if( $ShowImage ) ?> 
 <?php echo "<img src='http://localhost/exp/upload/$sidno.jpg'>"; ?> <br><br>

  <font size="1"><B>ID Number:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['IDNO']; ?> &nbsp;&nbsp;&nbsp;<br>

  <font size="1"><B><B>Year:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['YEAR']; ?> &nbsp;&nbsp;&nbsp; <br>
     <B>Section:</B>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['SECTION']; ?> &nbsp;&nbsp;&nbsp;<br>


<?php if( $ShowLastName ) ?>
  <font size="1"><B>Lastname:</B>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['LASTNAME']; ?>&nbsp;&nbsp;&nbsp;<br>

  <?php   if( $ShowFirstName ) ?>
         <font size="1"><B><B>Firstname:</B>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['FIRSTNAME']; ?> &nbsp;&nbsp;&nbsp;<br>

 <?php if( $ShowMidName ) ?>
         <font size="1"><B><B>Midname:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['MI']; ?> &nbsp;&nbsp;&nbsp;<br>


    <?php if( $ShowAddress ) ?>
         <font size="1"><B><B>Address:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['ADDRESS']; ?> &nbsp;&nbsp;&nbsp;<br>


    <?php if( $ShowGender ) ?>
         <font size="1"><B><B>Gender:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['GENDER']; ?> &nbsp;&nbsp;&nbsp;<br>




    <?php if( $ShowReligion ) ?>
         <font size="1"><B><B>Religion:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['RELIGION']; ?> &nbsp;&nbsp;&nbsp;<br>


    <?php if( $ShowBday ) ?>
         <font size="1"><B><B>Birthday:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['BIRTHDAY']; ?> &nbsp;&nbsp;&nbsp;<br>


    <?php if( $ShowContact) ?>
         <font size="1"><B><B>Contact Number</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['S_CONTACTNUM']; ?> &nbsp;&nbsp;&nbsp;<br>


<?php } ?>


<?php while($row = mysql_fetch_array($result3)) 
{ 
?>
  <br>
<br>
 <?php if( $ShowMother or $ShowFather or $ShowMotherOcc or $ShowFather_Occ  or $ShowParentAddress or $ShowParentContact ) ?>

<font size="3"><b><u>Parent Information</br></b></u></font><br>


   <tr>
     <?php  if( $ShowMother ) ?>

         <font size="1"><B><B>Mother:</B>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['MOTHER']; ?>&nbsp;&nbsp;&nbsp;<br>


    <?php     if( $ShowMotherOcc ) ?>
         <font size="1"><B><B>Mother Occupation:</B>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['MOTHER_OCCUPATION']; ?>&nbsp;&nbsp;&nbsp;<br>
}


<?php  while($row = mysql_fetch_array($result4)) 
{  ?>

        <?php   if( $ShowFather ) ?>
         <font size="1"><B><B>Father:</B>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['FATHER']; ?> &nbsp;&nbsp;&nbsp;<br>

         <?php  if( $ShowFather_Occ ) ?>
         <font size="1"><B><B>Father Occupation:</B>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row['FATHER_OCCUPATION']; ?>&nbsp;&nbsp;&nbsp;<br>

<?php } ?>
<?php while($row = mysql_fetch_array($result5)) 
{ ?>
        <?php   if( $ShowParentAddress ) ?>
         <font size="1"><B><B>Parent Address:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['P_ADDRESS']; ?> &nbsp;&nbsp;&nbsp;<br>


         <?php    if( $ShowParentContact ) ?>
         <font size="1"><B><B>Parent Contact:</B>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $row['P_CONTACTNUM']; ?> &nbsp;&nbsp;&nbsp;<br>


<?php } ?> 


<?php mysql_close($con);  ?> 
</div>
<div id="nav">
<form>
<input type="button" value="Print" onClick="window.print();" /> 
</form>
</div>

3 个答案:

答案 0 :(得分:5)

while ($row = mysql_fetch_array($result3)) {

此循环永远不会关闭。

以下是我用来查找问题的方法:

  1. http://www.phpformatter.com/并将您提供的代码复制粘贴到框中。
  2. 选中“选项”下的“控制结构后注释”框。
  3. 它是否格式化了代码。
  4. 通过并查找没有匹配结束评论的结构。
  5. 到目前为止还没有完全自动化,但是在每个结束括号后面的注释告诉你解析器认为与该大括号匹配的内容是追踪缺失/不匹配大括号的天赐之物。

    但是,在将来,我强烈建议首先尝试整齐地编写/评论您的代码 - 这有助于找到并避免这些类型的错误。

答案 1 :(得分:1)

正如戴维所说,有一个缺席的支撑。但它遗漏的原因是它没有被PHP标记括起来,没有封闭的PHP标记,PHP解释器将不会考虑代码

更改

}

<?php } ?>

答案 2 :(得分:0)

不,工具没有任何方法可以找到错误。它只是一个未封闭的块,并且工具无法知道您关闭块的位置(在大多数情况下)。

最好的办法是以缩进块的方式格式化代码,并使用突出显示匹配大括号的编辑器。这应该可以更容易地匹配你错过的那个。

相关问题