我在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> <?php echo $row['IDNO']; ?> <br>
<font size="1"><B><B>Year:</B> <?php echo $row['YEAR']; ?> <br>
<B>Section:</B> <?php echo $row['SECTION']; ?> <br>
<?php if( $ShowLastName ) ?>
<font size="1"><B>Lastname:</B> <?php echo $row['LASTNAME']; ?> <br>
<?php if( $ShowFirstName ) ?>
<font size="1"><B><B>Firstname:</B> <?php echo $row['FIRSTNAME']; ?> <br>
<?php if( $ShowMidName ) ?>
<font size="1"><B><B>Midname:</B> <?php echo $row['MI']; ?> <br>
<?php if( $ShowAddress ) ?>
<font size="1"><B><B>Address:</B> <?php echo $row['ADDRESS']; ?> <br>
<?php if( $ShowGender ) ?>
<font size="1"><B><B>Gender:</B> <?php echo $row['GENDER']; ?> <br>
<?php if( $ShowReligion ) ?>
<font size="1"><B><B>Religion:</B> <?php echo $row['RELIGION']; ?> <br>
<?php if( $ShowBday ) ?>
<font size="1"><B><B>Birthday:</B> <?php echo $row['BIRTHDAY']; ?> <br>
<?php if( $ShowContact) ?>
<font size="1"><B><B>Contact Number</B> <?php echo $row['S_CONTACTNUM']; ?> <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> <?php echo $row['MOTHER']; ?> <br>
<?php if( $ShowMotherOcc ) ?>
<font size="1"><B><B>Mother Occupation:</B> <?php echo $row['MOTHER_OCCUPATION']; ?> <br>
}
<?php while($row = mysql_fetch_array($result4))
{ ?>
<?php if( $ShowFather ) ?>
<font size="1"><B><B>Father:</B> <?php echo $row['FATHER']; ?> <br>
<?php if( $ShowFather_Occ ) ?>
<font size="1"><B><B>Father Occupation:</B> <?php echo $row['FATHER_OCCUPATION']; ?> <br>
<?php } ?>
<?php while($row = mysql_fetch_array($result5))
{ ?>
<?php if( $ShowParentAddress ) ?>
<font size="1"><B><B>Parent Address:</B> <?php echo $row['P_ADDRESS']; ?> <br>
<?php if( $ShowParentContact ) ?>
<font size="1"><B><B>Parent Contact:</B> <?php echo $row['P_CONTACTNUM']; ?> <br>
<?php } ?>
<?php mysql_close($con); ?>
</div>
<div id="nav">
<form>
<input type="button" value="Print" onClick="window.print();" />
</form>
</div>
答案 0 :(得分:5)
while ($row = mysql_fetch_array($result3)) {
此循环永远不会关闭。
以下是我用来查找问题的方法:
到目前为止还没有完全自动化,但是在每个结束括号后面的注释告诉你解析器认为与该大括号匹配的内容是追踪缺失/不匹配大括号的天赐之物。
但是,在将来,我强烈建议首先尝试整齐地编写/评论您的代码 - 这有助于找到并避免这些类型的错误。
答案 1 :(得分:1)
正如戴维所说,有一个缺席的支撑。但它遗漏的原因是它没有被PHP
标记括起来,没有封闭的PHP
标记,PHP解释器将不会考虑代码
更改
}
到
<?php } ?>
答案 2 :(得分:0)
不,工具没有任何方法可以找到错误。它只是一个未封闭的块,并且工具无法知道您关闭块的位置(在大多数情况下)。
最好的办法是以缩进块的方式格式化代码,并使用突出显示匹配大括号的编辑器。这应该可以更容易地匹配你错过的那个。