signup.php page doesn't work

I have a signup.php page being used for collect online subscriber's email. The code is as below.

When I comment out line 31 -43, it can show part of the page, but when I enable these lines, it doesn't show anything, Could somebody help me take a look?

Thank you.


[root@point logs]# vi /var/www/bbemod/signup.php
<?php include "header.php"; ?>

<div class="umTop">Signup for newsletter</div>


<div class="umcont">

<?php
    if (isset($_GET['addr']))
    {
        $email = $_GET['addr'];

        if (validate_email_addr($email))
        {
                Noemail::delete($email);

                $sub = new Subscriber();
                if (! Subscriber::find($email, $sub)) {
                $sub->email_addr = $email;
                Subscriber::save($sub);
                }
                echo "<p>Thank you. " . $email . " has been added to our subscriber list</p>";
        }
        else {
                echo '<p>You must enter a valid email address. Please <a href="' . $_SERVER['PHP_SELF'] . '">try again</a></p>';
        }
    }
    else {


      <form action="signup.php" method="GET">
        <input type="hidden" name="reason" value="Unsubscribe" >

          <p class="bulletText pb10">Email</p>
          <p class="pb15">
              <input name="addr" type="text" class="textBox" value="Enter your email here"
                     onfocus="javascript:if(this.value=='Enter your email here'){this.value=''}"
                     onblur="javascript:if(this.value==''){this.value='Enter your email here'}" size="20" >
          </p>
          <p class="pb15">
              <input type="submit" name="signup" value="" class="signUp"/>
          </p>
      </form>


    }
?>

</div>

<?php include "footer.php"; ?>

Open in new window

Jason YuAsked:
Who is Participating?
 
Chris StanyonCommented:
Just take lines 31-45 out of the PHP code block, so your code would look like this:

    else {
?>

      <form action="signup.php" method="GET">
        <input type="hidden" name="reason" value="Unsubscribe" >

          <p class="bulletText pb10">Email</p>
          <p class="pb15">
              <input name="addr" type="text" class="textBox" value="Enter your email here"
                     onfocus="javascript:if(this.value=='Enter your email here'){this.value=''}"
                     onblur="javascript:if(this.value==''){this.value='Enter your email here'}" size="20" >
          </p>
          <p class="pb15">
              <input type="submit" name="signup" value="" class="signUp"/>
          </p>
      </form>

<?php 
    }
?>

</div>

<?php include "footer.php"; ?>

Open in new window


Notice that line 2 now closes off the PHP block. All the HTML that follows (your Form) is now back in a normal HTML block. Line 18 then opens up another PHP block so that you can finish of the if/else statement correctly.
0
 
bwasyliukCommented:
Greetings,

Since you are mixing PHP and HTML code, you have to remember that the PHP is running on the server, and the HTML is interpreted on the client (i.e. browser).

As a result, that section of code needs to be "echo 'ed" out or the PHP is probably mal-formed.

look at the way line 26 is setup.  PHP is echo'ing out the HTML code.

Let me know if you need further explanation.

Ben
0
 
Jason YuAuthor Commented:
I didn't get the point, you meant this line has problem:

echo '<p>You must enter a valid email address. Please <a href="' . $_SERVER['PHP_SELF'] . '">try again</a></p>';
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
bwasyliukCommented:
No, sorry that's not what I meant.

If you look at lines 23 and 26, you will see they start with the word echo.

This is a PHP command that is pushing out HTML code from the inside of the PHP block you are in.

Line 9 starting with <?php is the start of the PHP block, all the way down to line 48 the block ends with ?>.

So, since you are inside a PHP block, having the HTML code that you do from 32 to 44 will not display because you have not told PHP what to do with that information.

Your code should be wrapped in an echo, like :
  
echo '
    <form action="signup.php" method="GET">
        <input type="hidden" name="reason" value="Unsubscribe" >

          <p class="bulletText pb10">Email</p>
          <p class="pb15">
              <input name="addr" type="text" class="textBox" value="Enter your email here"
                     onfocus="javascript:if(this.value=='Enter your email here'){this.value=''}"
                     onblur="javascript:if(this.value==''){this.value='Enter your email here'}" size="20" >
          </p>
          <p class="pb15">
              <input type="submit" name="signup" value="" class="signUp"/>
          </p>
      </form>
  '; <!---- this is the end of your php echo ---->

Open in new window


Please note i do not expect the above code to work, i am illustrating a concept.  You will likely have issues with the inner single quotes within some of the HTML.

Ben
0
 
Ray PaseurCommented:
Lines 31-43 should be expected to cause a PHP parse error.  These lines are HTML, not PHP.  They must be encapsulated somehow before they can be used as a data string in the PHP script.  You might want to learn about HEREDOC notation.  Heed, but do not be put off by the warning label.
https://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

From this and some of your other questions, I think you might want to take a little time to get a foundation in how PHP works.  Originally it was supposed to be an easy language, but it has grown by topsy into a bizarre funhouse language with numerous stupefying quirks.  There are large parts of the language that are better left alone, and the process for intermixing PHP code and HTML documents is one of those parts fraught with errors.  "Just don't do that!" might be the best guidance I can give anyone.  As you get more advanced in the language, you will learn about templating concepts and you will find a way to use PHP and HTML together without the risks and errors and "spaghetti code" that plague novice developers.

This article can help you get started on a good footing.  It takes a while to learn all this stuff, so be patient with yourself!
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 
Jason YuAuthor Commented:
HI, Experts, thank you all for your efforts, I got it resolved by accepting Chris' solution.

"Just take lines 31-45 out of the PHP code block, so your code would look like this:"

by taking these lines out of php section, it works perfectly.

"
      <form action="signup.php" method="GET">
        <input type="hidden" name="reason" value="Unsubscribe" >

          <p class="bulletText pb10">Email</p>
          <p class="pb15">
              <input name="addr" type="text" class="textBox" value="Enter your email here"
                     onfocus="javascript:if(this.value=='Enter your email here'){this.value=''}"
                     onblur="javascript:if(this.value==''){this.value='Enter your email here'}" size="20" >
          </p>
          <p class="pb15">
              <input type="submit" name="signup" value="" class="signUp"/>
          </p>
      </form>
"

I will read the link Ray Paseur brought and sincere thanks for all the helpful replies and suggestions. You guys are the best!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.