PDA

View Full Version : Parse error: syntax error, unexpected $end



galtmilemedia
07-21-2012, 05:22 PM
Now getting the following error when I type in skinsenseminimedspa.com/manage.php:

Parse error: syntax error, unexpected $end in /home/skinsens/public_html/manage.php on line 117

Can someone help me out with this one? Below is the full code to the page.

<?php
include 'scripts/include.php';

//determine if they need to see the form or not
if (!$_POST)
{
//they need to see the form, create form block
$display_block = <<<END_OF_BLOCK
<form method="POST" action="{$_SERVER['PHP_SELF']}">
<p><label for="email">Your E-Mail Address:</label></br>
<input type="text" id="email" name="email" size="40" maxlength="150" /></p>

<fieldset>
<legend>Action:</legend></br>
<input type="radio" id="action_sub" name="action" value="sub" checked />
<label for="action_sub">subscribe</label></br>
<input type="radio" id="action_unsub" name="action" value="unsub" checked />
<label for="action_unsub">unsubscribe</label></br>
</fieldset>

<input name="submit" type="button" value="submit">
</form>
END_OF_BLOCK;
}
else if (($_POST) && ($_POST{'action'} == "sub"))
{
//trying to subscribe, validate email address
if ($_POST{'email'} == "")
{
header("Location: manage.php");
exit;
}
else
{
//connect to database
dbconnect();

//check that email is in list
emailChecker($_POST{'email'});

//get the mumber of results and do action
if (mysqli_num_rows($check_res) < 1)
{
//free result
mysqli_free_result($check_res);

//add record
$add_sql = "INSERT INTO subscribers (email) VALUES('".$safe_email."')";
$add_res = mysqli_query($mysqli, $add_sql) or die(mysqli_error($mysqli));
$display_block = "<p>Thanks for signing up!</p>";

//close connection to mysql
mysqli_close($mysqli);
}
else
{
//print failure message
$display_block = "<p>You're already subscribed!</p>";
}
}
}
else if (($_POST) && ($_POST{'action'} == "unsub"))
{
//trying to unsubscribe, validate email address
if ($_POST{'email'} == "")
{
header("Location: manage.php");
exit;
}
else
{
//connect to database
dbconnect();

//check that email is in the list
emailChecker($_POST{'email'});

//get the number of results and do action
if (mysqli_num_rows($check_res) < 1)
{
//free result
mysqli_free_result($check_res);

//print failure message
$display_block = "<p>Couldn't find your email address!</p>
<p>No action was taken.</p>";
}
else
{
//get value of ID from result
while ($row = mysqli_fetch_array($check_res))
{
$id = $row{'id'};
}

//unsubscribe the email address
$del_sql = "DELETE FROM subscribers WHERE id = ".$id;
$del_res = mysqli_query($mysqli_error($mysqli));
$display_block = "<p>You're unsubscribed!</p>";
}
mysqli_close($mysqli);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Subscribe/Unsubscribe to our Mailing List</title>
</head>

<body>
<h1>Subscribe/Unsubscribe to our Mailing List</h1>
<?php echo $display_block; ?>
</body>
</html> ***THIS IS LINE 117***

Fou-Lu
07-21-2012, 05:36 PM
There are two errors here. The first is that END_OF_BLOCK is preceded with whitespace, and the other is a mismatched closing }.
I'll reformat this so its easier to see it:


<?php
include 'scripts/include.php';

//determine if they need to see the form or not
if (!$_POST)
{
//they need to see the form, create form block
$display_block = <<<END_OF_BLOCK
<form method="POST" action="{$_SERVER['PHP_SELF']}">
<p><label for="email">Your E-Mail Address:</label></br>
<input type="text" id="email" name="email" size="40" maxlength="150" /></p>

<fieldset>
<legend>Action:</legend></br>
<input type="radio" id="action_sub" name="action" value="sub" checked />
<label for="action_sub">subscribe</label></br>
<input type="radio" id="action_unsub" name="action" value="unsub" checked />
<label for="action_unsub">unsubscribe</label></br>
</fieldset>

<input name="submit" type="button" value="submit">
</form>
END_OF_BLOCK; // <-- ERROR HERE
}
else if (($_POST) && ($_POST{'action'} == "sub"))
{
//trying to subscribe, validate email address
if ($_POST{'email'} == "")
{
header("Location: manage.php");
exit;
}
else
{
//connect to database
dbconnect();

//check that email is in list
emailChecker($_POST{'email'});

//get the mumber of results and do action
if (mysqli_num_rows($check_res) < 1)
{
//free result
mysqli_free_result($check_res);

//add record
$add_sql = "INSERT INTO subscribers (email) VALUES('".$safe_email."')";
$add_res = mysqli_query($mysqli, $add_sql) or die(mysqli_error($mysqli));
$display_block = "<p>Thanks for signing up!</p>";

//close connection to mysql
mysqli_close($mysqli);
}
else
{
//print failure message
$display_block = "<p>You're already subscribed!</p>";
}
}
}
else if (($_POST) && ($_POST{'action'} == "unsub"))
{
//trying to unsubscribe, validate email address
if ($_POST{'email'} == "")
{
header("Location: manage.php");
exit;
}
else
{
//connect to database
dbconnect();

//check that email is in the list
emailChecker($_POST{'email'});

//get the number of results and do action
if (mysqli_num_rows($check_res) < 1)
{
//free result
mysqli_free_result($check_res);

//print failure message
$display_block = "<p>Couldn't find your email address!</p>
<p>No action was taken.</p>";
}
else
{
//get value of ID from result
while ($row = mysqli_fetch_array($check_res))
{
$id = $row{'id'};
}

//unsubscribe the email address
$del_sql = "DELETE FROM subscribers WHERE id = ".$id;
$del_res = mysqli_query($mysqli_error($mysqli));
$display_block = "<p>You're unsubscribed!</p>";
}
mysqli_close($mysqli);
}
}
} //<--ERROR HERE
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Subscribe/Unsubscribe to our Mailing List</title>
</head>

<body>
<h1>Subscribe/Unsubscribe to our Mailing List</h1>
<?php echo $display_block; ?>
</body>
</html>


In the future please wrap your code in
tags. It would have identified immediately the heredoc issue, but wouldn't have identified the ending brace.