Help me with basic PHP syntax?

wut

New member
I'm getting "Parse error: syntax error, unexpected $end" as my error. I googled around a little bit and found its usually caused by missing ( or { but I can't find any. I'm fairly new to PHP and I just felt like making a style changer to see if I could. Here is the code:

<?php
$x = $_GET['x'];
if(isset($x))
{
if($x==1)
{
$style =<<<EOD
<style type="text/css">
#body
{
background:#ff0000;
}
</style>
EOD;
}
else if($x==2)
{
$style =<<<EOD
<style type="text/css">
#body
{
background:#0000ff;
}
</style>
EOD;
}
}
else
{
echo "choose style";
$style = <<<EOD
<style type="text/css">
#body
{
background:#cccccc;
}
</style>
EOD;
?>
<html>
<head>
<title>Style Changer</title>
</head>
<body>
<?php echo "$style" ?>
<div id="body">
<a href="index.php?x=1" alt="red">Click for red</a>
<a href="index.php?x=2" alt="blue">Click for blue</a>
</div>
</body>
</html>
 
Hmm...what about if you remove the quotations around your $style variable?

Like:
<?php echo $style; ?>

>Other than that...I know that EOD; doesn't allow any spaces or tabs before or after it...so make sure there are none in your actual php file - doesn't look like there are here though...
 
Back
Top