Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-21-2012, 05:22 PM   PM User | #1
galtmilemedia
New to the CF scene

 
Join Date: Jul 2012
Location: Austin, Texas
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
galtmilemedia is an unknown quantity at this point
Parse error: syntax error, unexpected $end

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***
galtmilemedia is offline   Reply With Quote
Old 07-21-2012, 05:36 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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 Code:
<?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 [php][/php] tags. It would have identified immediately the heredoc issue, but wouldn't have identified the ending brace.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:33 PM.


Advertisement
Log in to turn off these ads.