10 Replies - 8372 Views - Last Post: 27 November 2010 - 08:00 AM Rate Topic: -----

#1 bjarvi1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 08-January 10

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 09 May 2010 - 06:54 AM

I am making a php photo gallery script, but I keep getting the error in the topic title whenever I run the script in XAMPP. My code is below.

<?php
include 'config.inc.php';

//initialisation
$photo_upload_fields = ' ';
$counter = 1;

//More Fields = preupload.php?number_of_fields=20
$number_of_fields = (isset($_GET['number_of_fields'])) ? (int) ($_GET['number_of_fields']) : 5;

//Build ccategory list
$result = mysql_query('SELECT catetegory_id,category_name FROM gallery_category');
while($row = mysql_fetch_array($result)) {
	$photo_category_list .= <<<__HTML_END
	<tr><td>
		Photo {$counter} :
		<input name="photo_filename[]" type="file" />
	</td></tr>
	<tr><td>
		Caption:
		<textarea name="photo_caption[]" cols="30" rows="1"></textarea>
	</td></tr>
	__HTML_END;
	$counter++;
}
// Final Output
echo <<<__HTML_END
<html>
<head>
<title>Lets Upload Photos</title>
</head>
<body>
<form enctype="multipart/form-data"  
 action="upload.php" method="post"  
 name="upload_form">  
 <table width="90%" border="0"  
   align="center" style="width: 90%;">  
   <tr><td>  
     Select Category  
     <select name="category">  
     $photo_category_list  
     </select>  
   </td></tr>  
   <!—Insert the image fields here -->  
   $photo_upload_fields  
   <tr><td>  
     <input type="submit" name="submit"  
       value="Add Photos" />  
   </td></tr>  
 </table>  
</form>  
</body>  
</html>  
__HTML_END;
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

#2 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 09 May 2010 - 07:23 AM

The error is in your while loop. For your heredoc, you have the ending __HTML_END indented. You can't do that. The end marker for a heredoc block must start on the first character of the line. You can't have any whitespace before it, even if it's inside an indented block of code, or PHP won't recognize it.
Was This Post Helpful? 0
  • +
  • -

#3 bjarvi1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 08-January 10

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 09 May 2010 - 07:29 AM

It works, thanks, but now I get the error:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Photo Gallery\preupload.php on line 13
Was This Post Helpful? 0
  • +
  • -

#4 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 09 May 2010 - 07:35 AM

Try with-

$result = mysql_query('SELECT catetegory_id,category_name FROM gallery_category')
or die(mysql_error());



and see what happens. It will help you to figure out the problem.
Was This Post Helpful? 0
  • +
  • -

#5 bjarvi1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 08-January 10

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 09 May 2010 - 08:07 AM

stupid mistake, spelled category wrong :stupid:
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2913
  • View blog
  • Posts: 10,088
  • Joined: 08-August 08

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 09 May 2010 - 09:33 AM

FYI, this:
$qry = "SELECT...";
mysql_quer($qry);

is better than this:
mysql_query("SELECT...");

because when you run into trouble you can easily debug by doing this:
$qry = "SELECT...";
echo "<br>".$qry."<br>";
mysql_query($qry);

This post has been edited by CTphpnwb: 10 May 2010 - 05:12 PM
Reason for edit:: fixed spelling of mysql_query. Oops!

Was This Post Helpful? 3
  • +
  • -

#7 bjarvi1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 08-January 10

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 09 May 2010 - 10:43 AM

thanks for the tip
Was This Post Helpful? 0
  • +
  • -

#8 Guest_avaneesh*


Reputation:

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 27 November 2010 - 05:52 AM

I am getting this error in my php page.plz help


Parse error: syntax error, unexpected $end in C:\xampp\htdocs\SMS\indexsms.php on line 237


<?php
include("./Session/session.php");
include_once("./DBConnector/incConnection.inc");
$num=0;

if($_POST['username'])
{
if($_POST['username']!="super_user" && $_POST['password'] !="info")
{
	$sql_query="select login_loginname,login_password from login where login_loginname='".$_POST['username']."' and login_password='".$_POST['password']."'";
	$result=mysql_query($sql_query);
	$col_result=mysql_fetch_object($result);
		
	$login_loginname1=$col_result->login_loginname;
	$login_password1=$col_result->login_password;
	
	if(trim($_POST['username'])==trim($login_loginname1) && trim($_POST['password'])==trim($login_password1))
	{
		$num=mysql_num_rows($result);
	}
}
else
{
$num=1;
}


}

	$query_year=mysql_fetch_object(mysql_query("select sms_academic_year_id from sms_academic_year where sms_academic_year_syear<= '".date('Y-m-d')."' and sms_academic_year_eyear>='".date('Y-m-d')."' and sms_academic_year_flag=0"));
  $syear=$query_year->sms_academic_year_id;
   
if($num < 1) 
  { 
 	 session_destroy(); 

?>

<html>
<head>
	<TITLE>| Institute Management System |</TITLE>
	<meta name="description" content="Free Javascript component for HTML form validation at client-side">
	<meta name="keywords" content="Javascript validator, javascript, html, form, client side, netscape, explorer, IE, opera, form, fill, validation, format, date, time, submit, check, pattern, match">
	<meta name="robots" content="index,follow">
<script language="javascript" type="text/javascript" src="get_project.js"></script>
<style>
	a, A:link, a:visited, a:active
		{color: #0000aa; text-decoration: none; font-family: Tahoma, Verdana; font-size: 11px}
	A:hover
		{color: #ff0000; text-decoration: none; font-family: Tahoma, Verdana; font-size: 11px}
	p, tr, td, ul, li
		{color: #000000; font-family: Tahoma, Verdana; font-size: 11px}
	th
		{background: #DBEAF5; color: #000000;}
	.header1, h1
		{color: #ffffff; background: #4682B4; font-weight: bold; font-family: Tahoma, Verdana; font-size: 13px; margin: 0px; padding-left: 2px; height: 21px}
	.header2, h2
		{color: #000000; background: #DBEAF5; font-weight: bold; font-family: Tahoma, Verdana; font-size: 12px;}
	.intd
		{color: #000000; font-family: Tahoma, Verdana; font-size: 11px; padding-left: 15px;}
	.wcell
		{background: #FFFFFF; vertical-align: top}
	.ctrl
		{font-family: Tahoma, Verdana, sans-serif; font-size: 12px; width: 100%; background:#FFFFFF;}
	.btnform
		{border: 0px; font-family: tahoma, verdana; font-size: 12px; background-color: #DBEAF5; width: 100%; height:18px; text-align: center; cursor: hand;}
	.btn
		{background-color: #DBEAF5; padding: 0px;}
	textarea, select,input
		{font: 9px Verdana, arial, helvetica, sans-serif; background-color: #DBEAF5;}
	.bdr
{
    BORDER-RIGHT: #D9DC6B 2px solid;
    BORDER-TOP: #D9DC6B 2px solid;
    BORDER-LEFT: #D9DC6B 2px solid;
    BORDER-BOTTOM: #D9DC6B 2px solid
}	
.btnform
		{border: 0px;  font-family: tahoma, verdana; font-size: 12px; background-color: #DBEAF5; width: 100%; height:18px; text-align: center; cursor: hand;}		
	/* classes for validator */
	.tfvHighlight
		{color: #CEA639;}
	.tfvNormal
		{color: black;}
	.inputHighlighted
		{color: #CEA639;}
	.inputNormal
		{color: black;}
</style>
<script language="Javascript" src="validator.js"></script>
<script language='javascript'>
function check_ayear()
{
	
	if(document.getElementById('txt_sy_id').value!=document.getElementById('cmb_ayear_id').value)
	{	
		confirm('Year does not match current Academic Year, Do you really want to proceed');
	}
	
}
function chk()
{
   if(document.getElementById('cmbproj_id').value=="")
	{
	 alert("Please select propject");
	 document.getElementById('cmbproj_id').focus();
	 return false;
	}
	return true;
}	
</script>

</head>

<body bgcolor="white" leftmargin="15" topmargin="100" rightmargin="15" bottommargin="15" marginwidth="15" marginheight="15" class="tfvHighlight">

<form method="post" name="login" onsubmit="return v.exec()">
<input type="hidden" name="txt_sy" id="txt_sy_id" size="10" value="<? print $syear; ?>" class="ctrl">

  <table width="249" height="383" border="0" align="center" cellpadding="0" cellspacing="0" class="bdr">
    <tr> 
     <td height="383" background="images/login.gif"  valign="top"><table width="76%" height="101"  border="0" cellpadding="2" cellspacing="1">
  <tr >
    <td id="t_uname" width="98%">&nbsp;Login Name:<span class="inputHighlighted">*</span>
      <input type="text" name="username" size="10"   value="" class="ctrl"  onchange="showproj(this.value,'div_proj')"/></td>
    <td width="2%">&nbsp;</td>
  </tr>
  <tr >
    <td id="t_password">&nbsp;Password:<span class="inputHighlighted">*
      <input type="password" name="password" size="10" class="ctrl" value="" />
    </span></td>
    <td>&nbsp;</td>
  </tr>
  <tr >
    <td id="t_project">project:<span class="inputHighlighted">*</span><div id="div_proj"><select name="cmbproj" id="cmbproj_id" class="ctrl">
	<option value=" ">Select</option>
	</select></div></td>
    <td>&nbsp;</td>
  </tr>
  <tr >
    <td id="t_ayear">&nbsp;Academic Year:
      <select name="cmb_ayear" id="cmb_ayear_id" class="ctrl" onchange="check_ayear();">
        <?
					$query=mysql_query("select * from sms_academic_year where sms_academic_year_flag=0");
					while($res_user=mysql_fetch_object($query))
					{
						if($syear==$res_user->sms_academic_year_id)
						{
						?>
        <option value="<? print $res_user->sms_academic_year_id;?>" selected="selected"><? print date('d/m/Y',strtotime($res_user->sms_academic_year_syear))." - ".date('d/m/Y',strtotime($res_user->sms_academic_year_eyear)); ?></option>
        <? 
						}
						else
						{
						?>
        <option value="<? print $res_user->sms_academic_year_id;?>"><? print date('d/m/Y',strtotime($res_user->sms_academic_year_syear))." - ".date('d/m/Y',strtotime($res_user->sms_academic_year_eyear)); ?></option>
        <?
						}
					}?>
      </select></td>
    <td>&nbsp;</td>
  </tr>
</table>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<table width="100%" border="0" cellpadding="2" cellspacing="1" >
  <!--input type="image" src="img/login_final.gif" alt="" width="79" height="22" border="0" name="Submit"-->
  <tr >
    <td width="80%" height="26" id="t_ayear">&nbsp;</td>
    <td  width="20%" align="right"><input type="submit" value="Login" name="btn_log" class="btnform">
	
	</td>
  </tr>
</table>
</td>
    </tr>
  </table>

</form>
<p>
  <script>
// form fields description structure
var a_fields = {
	'username' : {
		'l': 'Name',  // label
		'r': false,    // required
		'f': 'email',  // format (see below)
		't': 't_uname',// id of the element to highlight if input not validated
		
		'm': null,     // must match specified form field
		'mn': 2,       // minimum length
		'mx': null       // maximum length
	},
	'username' : {'l':'Login Name','r':true,'t':'t_uname'},
	'password' : {'l':'Password','r':true,'f':'alphanum','t':'t_password'},
	'cmbproj' : {'l':'Project','r':true,'f':'alphanum','t':'t_project'}
},
o_config = {
	'to_disable' : ['Submit'],
	'alert' : 1
}

// validator constructor call
var v = new validator('login', a_fields, o_config);

</script>
</p>
</body>
</html>
 <?
 	if($_POST['username'] && $_POST['password'] && $num=='0')
 	{
 		print("<table align='center'><tr>
      <td align='center'><font color='red' size='2'><b>Please Check Login Name/Password...</b></font></td></tr></table>");
	}
 }
 else
 {
      //session_register("auth_type");
    $cmb_type=mysql_fetch_object(mysql_query("select sms_auth_project_usertype from sms_auth_project where  user_id='".$_POST["username"]."'"));
      $_SESSION["auth_type"]=$cmb_type->sms_auth_project_usertype;
       
		session_register("login_time");
		session_register("username"); 
		session_register("password"); 
		session_register("academic_year"); 
		session_register("ses_projects"); 
		 
		 $_SESSION['username']=$_POST["username"]; 
 		 $_SESSION['password']=$_POST["password"];
 		 $_SESSION['academic_year']=$_POST["cmb_ayear"]; 
  		$_SESSION['ses_projects']=$_POST["cmbproj"]; 
		
	    $_SESSION["login_time"]=date('h:i:s A');
		print("<script language='javascript'>window.location.href='./main_module.php';</script>");	
 }
 
 ?>//line 237


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 27 November 2010 - 06:11 AM

Was This Post Helpful? 0

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 27 November 2010 - 06:15 AM

The error is because the PHP interpreter found the ending ?> when it did not expect it; i.e. it was expecting a }.

I'll let CTphpnwb rip you a new one for the lack of code separation, but your code is otherwise crappy because it's ripe for SQL injection and you store passwords in plaintext in the database.
Was This Post Helpful? 0
  • +
  • -

#10 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2913
  • View blog
  • Posts: 10,088
  • Joined: 08-August 08

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 27 November 2010 - 07:49 AM

Holy code mingling, Batman! You've got html, css, javascript, and php all in one file. I'm shocked, shocked to find that you have trouble!

Start thinking about separating them. In fact, make that your number one priority.
Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\Pho

Posted 27 November 2010 - 08:00 AM

I knew I could count on you, CTphpnwb :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1