tags:

views:

26

answers:

3

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'&gt;"; ?> <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>
A: 

No, there isn't really any way a tool could find the error. It's just an unclosed block and there is no way a tool can know where you meant to close a block (in most cases).

Your best bet is to format the code in a way that indents blocks, and use an editor that highlights matched braces. That should make it easier to match up the one you've missed.

Brenton Alker
what would you recommend that I use for editing? I'm currently using dreamweaver
@user no, there is a way. reduce your code by portions until it starts to run well, to reveal the problem part. But formatting is always good too. Note that editor won't do your job. it is your duty to properly format the code.
Col. Shrapnel
+5  A: 
while ($row = mysql_fetch_array($result3)) {

This loop is never closed.

Here's the method I used to find the issue:

  1. Went to http://www.phpformatter.com/ and copy-pasted the code you supplied into the box.
  2. Checked the "Comment after control structures" box under "Options".
  3. Had it format the code.
  4. Went through and looked for the structure that didn't have a matching end comment.

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.

Amber
The control structure comment is a very neat feature. I wish they did a better job at formatting code however!
erisco
Agreed. I don't actually use that formatter for formatting code, it's just handy for the matching feature.
Amber
thanks for the resource man.
+1  A: 

As Dav mentioned there is a missing closing brace. But the reason why its missing is that it has not been enclosed in PHP tags, without the enclosing PHP tags the code will not be considered by the PHP interpreter

Change

}

to

<?php } ?>
codaddict