I’m having trouble with this error in php:
Parse error: syntax error, unexpected $end in J:\Server\xampplite\htdocs\exp\printact.php on line 172
It might be a lack of bracket or something. Is there any tool that could help me pin point where exactly the error is?
EDIT:
Here’s the code, its a mess:)
<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>
This loop is never closed.
Here’s the method I used to find the issue:
It’s not fully automated by far, but having the comments after each closing brace to tell you what the parser believes is matching with that brace is a godsend for tracking down missing/mismatched braces.
In the future, however, I highly recommend trying to format/comment your code neatly in the first place – it helps to both find and avoid these kinds of errors.