Help With PHP Within DIV

Discussion in 'PHP' started by evanc93, Oct 31, 2010.

  1. #1
    Hello everybody! I am in the process of adding a shoutbox to my site. I am trying to make it so that when a member is logged in, the shout box form will be shown. And when a member is not logged in then it just shows a "Login To Chat" message. I am doing so with the php code below.

    http://pastebin.com/nNThRUAL

    This PHP code, however, is within a DIV and i cant seem to get the div that this code falls between to close.

    Please help and thanks in advance.
     
    evanc93, Oct 31, 2010 IP
  2. leh

    leh Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Putting all the html in an echo like that is just a bad idea. It's much better to just close the php tag right after the IF statement.
    ex:

    
    <?php if(isset($_SESSION['username']) && isset($_SESSION['password'])): ?>
    --- html stuff ---
    <?php else: ?>
    --- other html stuff ---
    <?php endif; ?>
    
    Code (markup):
    Anyway I found a problem with your code,
    on lines 22 and 23 you are opening new php blocks but you are already in one.

    change those lines to:
    
    <input type='hidden' id='token' name='token' value='". $token ."' />
    
    Code (markup):
    and
    
    <input type='hidden' id='name' name='name' value='". $mem_name ."' />
    
    Code (markup):
     
    leh, Nov 1, 2010 IP
  3. evanc93

    evanc93 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks leh for the quick response. I feel like such an idiot as I had already put a big block of html between php on another page of my site, using the method you replied with.

    Anyway thanks again for helping!
     
    evanc93, Nov 1, 2010 IP