Syntax error:::unexpected $end

I got an error while run this below code like:::
Parse error: syntax error, unexpected $end on line 136

Can any one help me regarding this error…
This is the code i used.


<?php
function convertstring($src)
{
            $dest=trim(eregi_replace("[[:space:]]{2}"," ","$src"));
            for($i=1;$i<48;$i++)
             {
              $chr=chr($i);
              $dest=str_replace($chr," ",$dest);
             }
            for($i=58;$i<65;$i++)
             {
              $chr=chr($i);
              $dest=str_replace($chr," ",$dest);
             }
            for($i=91;$i<96;$i++)
             {
              $chr=chr($i);
              $dest=str_replace($chr," ",$dest);
             }
            for($i=123;$i<256;$i++)
             {
              $chr=chr($i);
              $dest=str_replace($chr," ",$dest);
             }
            $dest=trim(eregi_replace("[[:space:]]{3}"," ","$dest"));
            $dest=trim(eregi_replace("[[:space:]]{2}"," ","$dest"));
            $dest=str_replace(" ","-","$dest");
            return $dest;
}
include('dbase.conf');
mysql_connect($server,$username,$password);
mysql_select_db($database);
$rid=$_POST['rid'];
$pdf=$HTTP_POST_FILES['pdf']['tmp_name'];
$img1= $HTTP_POST_FILES['image1']['tmp_name'];
$img2= $HTTP_POST_FILES['image2']['tmp_name'];
$img3= $HTTP_POST_FILES['image3']['tmp_name'];
$img4= $HTTP_POST_FILES['image4']['tmp_name'];
$query="select * from Article where rec_id='$rid'";
$result=mysql_query($query);
$docdata=mysql_fetch_row($result);
$dirname="Article/".$rid;
 if(!is_dir($dirname))
 {
 $resul=mkdir($dirname,0777);
 if(!$resul)
 print("Error:Couldnot create Directory");
 }
$flag=0;
$imgflag=0;
if(isset($img1)&&($img1!="")&&($HTTP_POST_FILES['image1']['type']!="image/gif")&&($HTTP_POST_FILES['image1']['type']!="image/jpeg"))
 $imgflag=1;
else if(isset($img2)&&($img2!="")&&($HTTP_POST_FILES['image2']['type']!="image/gif")&&($HTTP_POST_FILES['image2']['type']!="image/jpeg"))
 $imgflag=1;
else if(isset($img3)&&($img3!="")&&($HTTP_POST_FILES['image3']['type']!="image/gif")&&($HTTP_POST_FILES['image3']['type']!="image/jpeg"))
 $imgflag=1;
else if(isset($img4)&&($img4!="")&&($HTTP_POST_FILES['image4']['type']!="image/gif")&&($HTTP_POST_FILES['image4']['type']!="image/jpeg"))
 $imgflag=1;
if($imgflag==1)
{
print<<<END1
<script language="Javascript">
alert("Image files should be of gif/jpeg format");
history.go(-1);
</script>
END1;
}
if(isset($pdf)&&($pdf!=""))
{
$flag=1;
$name = $HTTP_POST_FILES['pdf']['name'];
$extension=explode(".",$name);
$pdf=$rid.".".$extension[1];
copy($HTTP_POST_FILES['pdf']['tmp_name'],"Article/".$pdf);
$query1="update Article set pdfname='$pdf' where rec_id='$rid'";
$result1=mysql_query($query1);
if(!$result1)
die('Invalid Query: '. mysql_error());
}
if(isset($img1)&&($img1!=""))
{
$flag=1;
$im1 = $HTTP_POST_FILES['image1']['name'];
copy($HTTP_POST_FILES['image1']['tmp_name'],"Article/".$rid ."/".$im1);
$query1 = "update Article set img1='$im1' where rec_id='$rid'";
$result1=mysql_query($query1);
if(!$result1)
	die('Invalid Query: '. mysql_error());
}
if(isset($img2)&&($img2!=""))
{
$flag=1;
$im2 = $HTTP_POST_FILES['image2']['name'];
copy($HTTP_POST_FILES['image2']['tmp_name'],"Article/".$rid."/".$im2);
$query1 = "update Article set img2='$im2' where rec_id='$rid'";
$result1=mysql_query($query1);
if(!$result1)
	die('Invalid Query: '. mysql_error());
}
if(isset($img3)&&($img3!=""))
{
$flag=1; $im3 = $HTTP_POST_FILES['image3']['name'];
copy($HTTP_POST_FILES['image3']['tmp_name'],"Article/".$rid."/".$im3);
$query1 = "update Article set img3='$im3' where rec_id='$rid'";
$result1=mysql_query($query1);
if(!$result1)
	die('Invalid Query: '. mysql_error());
}
if(isset($img4)&&($img4!=""))
{
 $flag=1;
 $im4 = $HTTP_POST_FILES['image4']['name'];
 copy($HTTP_POST_FILES['image4']['tmp_name'],"Article/".$rid."/".$im4);
 $query1 = "update Article set img4='$im4' where rec_id='$rid'";
 $result1=mysql_query($query1);
 if(!$result1)
	die('Invalid Query: '. mysql_error());
}
if($flag==1)
{
 print<<<END
 <script language="JavaScript">
 alert("Upload is Successful");
 window.location='path to specific page';
 </script> END;
}
else
{
 print<<<END2
 <script language="JavaScript">
 alert("No file Entered!!!");
 window.location='path to specific page';
 </script>
 END2;
}
?>

Make sure you close all your IF statements, you’re probably missing a } somewhere…

Also, when using heredoc, the terminating identifier (e.g. END; ) has to be on it’s own line, with no whitespace.

Wrong:


 print<<<END
 <script language="JavaScript">
 alert("Upload is Successful");
 window.location='path to specific page';
 </script> END; 

Right:


print<<<END
 <script language="JavaScript">
 alert("Upload is Successful");
 window.location='path to specific page';
 </script> 
END; 

problem with heredoc END; only.
i solved the problem.
Thank you.