Computing.Net > Forums > Web Development > syntax error, unexpected $end

syntax error, unexpected $end

Reply to Message Icon

Original Message
Name: rsasalm
Date: October 22, 2005 at 02:41:06 Pacific
Subject: syntax error, unexpected $end
OS: Win XP
CPU/Ram: P4
Comment:

Hi all,

I am new to PHP and hope someone can help me.
I have a very simple script as below and when I run this I get the following error:

Parse error: syntax error, unexpected $end in c:\wamp\www\test\index.php on line 59
Line 59 is a blank line.
**********************************************
<?php
include("config.inc.php"); // here I connect to database and it works fine


$result = mysql_query( "SELECT category_id,category_name FROM gallery_category" );
while( $row = mysql_fetch_array( $result ) )
{
$photo_category_list .=<<<__HTML_END
<option
value="$row[0]">$row[1]</option>\n
__HTML_END;
}


mysql_free_result( $result );

// Final Output
echo <<<__HTML_END

<html>
<head>
<title>Gallery View</title>
</head>
<body>
<form enctype='multipart/form-data' action='index.php' method='post' name='upload_form'>
<table width='100%' border='0' align='center' style='width: 100%;'>

<tr>
<td>
Select Product Category:
</td>
</tr>

<tr>
<td>
<select name='category'>
$photo_category_list
</select>
</td>
</tr>
<tr>
<td >
<input type='submit' VALUE="GO" />
</td>
</tr>


</table>
</form>

</body>
</html>

__HTML_END;
?>

***************************************************
I even searched for the answer on the internet and most of time the only answer I found is the some
closing braces are missing.
But as my code is very simple I don't see any such misstake.
Can someone see in my code that what else I am missing.
thanks for help
regards
/rsasalm


Report Offensive Message For Removal

Response Number 1
Name: rsasalm
Date: October 22, 2005 at 08:46:23 Pacific
Subject: syntax error, unexpected $end
Reply: (edit)

Hi all again,

Haven't got any response and still waiting for if someone can help in solving my problem.

The code I am using is taken from the site:

http://www.sitepoint.com/article/php-gallery-system-minutes/2

If I run the application found at the above link, it works but not mine the small one script

Any comments
thanks in advance
regards
/rsasalm


Report Offensive Follow Up For Removal

Response Number 2
Name: Michael J (by mjdamato)
Date: October 22, 2005 at 09:07:10 Pacific
Subject: syntax error, unexpected $end
Reply: (edit)

What version of PHP are you running your code on? The <<< are not supported priot to PHP4.

Have you tried to do any trouble shooting? It's not rocket science. Just remove/comment out small sections until you no longer get the error. Then you know where the error is occuring. You just need to be sure that you don't comment out just the beginning or end of a loop/function/etc.

In this case I would remove the entire section of Final Output. If that works, then comment out the inside of the while function. Etc., etc.

Michael J


Report Offensive Follow Up For Removal

Response Number 3
Name: rsasalm
Date: October 22, 2005 at 09:39:58 Pacific
Subject: syntax error, unexpected $end
Reply: (edit)

I am using PHP version : 5.0.4.
I have tested the application found
http://www.sitepoint.com/article/php-gallery-system-minutes/2

which uses the same code
while( $row = mysql_fetch_array( $result ) )
{
$photo_category_list .=<<<__HTML_END
<option
value="$row[0]">$row[1]</option>\n
__HTML_END;
}

and it works but not in my script.
I have tested with add/remove code with for trouble shooting.
if I remove the lines
$photo_category_list .=<<<__HTML_END
<option
value="$row[0]">$row[1]</option>\n
__HTML_END;


and put something else in the while loop
like echo "Hello world"
I can see that "Hello world" string apprears
in the web.
Any comments
regards
/rsasalm



Report Offensive Follow Up For Removal

Response Number 4
Name: Michael J (by mjdamato)
Date: October 22, 2005 at 11:13:33 Pacific
Subject: syntax error, unexpected $end
Reply: (edit)

Try changing that line to this:

$photo_category_list .= '<option
value="'.$row[0].'">'.$row[1].'</option>\n';


Michael J


Report Offensive Follow Up For Removal

Response Number 5
Name: rsasalm
Date: October 22, 2005 at 12:29:22 Pacific
Subject: syntax error, unexpected $end
Reply: (edit)

Thanks Micael for reply,

Now I can see that drop down list is filled with two values "family" and "friends" (see below for explanation) and which i correct.

Now I go back to my first mail.
where I have a code line
$result = mysql_query( "SELECT category_id,category_name FROM gallery_category"

where $result variable contain 2 rows as below
row[0] row[1]
(int id) (text name)
R1: 1 family
R2: 2 freinds


Now in dropdown list apprears both family and friends.
When I click on submit button "Go" (see my first mail) and do echo dropdown list values at the top of the script as below:
$cid = (int)($_GET['category']);
echo $cid;

I always get "0" value(no matter if I choose family or friends) why??
thanks for help
regards
/rsasalm


Report Offensive Follow Up For Removal


Response Number 6
Name: Michael J (by mjdamato)
Date: October 22, 2005 at 14:09:13 Pacific
Subject: syntax error, unexpected $end
Reply: (edit)

I don't see int as a valid PHP operator (there is an intval)

Again you need to go back to basic trouble shooting. That first line is trying to modify the submitted value in someway (using the int). Just have it echo the posted value to see if it is coming across correctly:

echo $_GET['category'];

If that works, then try using (intval) instead of (int)

Michael J


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: syntax error, unexpected $end

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software