Fix my php....real simple I am sure

Discussion in 'PHP' started by journeyoftheanimals, Nov 30, 2007.

  1. #1
    I am working on placing a forum login box on the index of my site. Here is the code I am working with .

    
    <?php
    
    if($mybb->user['uid'])
    {
    ��// The user is logged in, say Hi
    [COLOR="Red"]echo "Hey, $mybbuser[username].<br>[/COLOR]
    Thanks for logging in.";
    }
    else
    {
    ��// The user is not logged in, Display the form
    echo "<form action='petchat/member.php' method='post'>
    Username: <input type='text' name='username' size='25' maxlength='30' /><br />
    Password: <input type='password' name='password' size='25' />
    <input type='hidden' name='action' value='do_login'>
    <input type='hidden' name='url' value='index.php' />
    <input type='submit' class='submit' name='submit' value='Login' /></form><br>";
    }
    ?>
    Code (markup):

    The error I get is
    
    Parse error: syntax error, unexpected T_ECHO in /home/journey/public_html/overhau2.php on line 105
    Code (markup):
    Line 105 has been highlighted in red.

    Thank you for any help you can give


    Adam Burgi
     
    journeyoftheanimals, Nov 30, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try replacing it with this:
    
    echo "Hey, ".$mybbuser['username']."<br>Thanks for logging in.";
    
    Code (markup):
    p.s. you have some kind of "??" characters in the code, they should be removed
     
    hogan_h, Nov 30, 2007 IP
  3. Crux

    Crux Well-Known Member

    Messages:
    704
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    130
    #3
    try this :)

     
    Crux, Nov 30, 2007 IP
  4. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That won't work, first you forgot '.' to concatenate the strings and second the "\n" is no replacement for "<br />", it will make line break in the source code, yeah, but it won't be displayed as linebreak on the website.
     
    hogan_h, Nov 30, 2007 IP
  5. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Could it not also be the fact that you have a double question mark apparently doing nothing above it? It could be trying to parse them as a double ternary operator.
     
    TwistMyArm, Nov 30, 2007 IP
  6. journeyoftheanimals

    journeyoftheanimals Well-Known Member

    Messages:
    339
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #6
    Thank you everyone.

    echo "Hey, $mybbuser[username].<br>

    It did seem to be the "." took that out and it works.....well sort of. It is supposed to show who you are signed in as once you are signed in. Ehhhh at least I have gotten somewhere.
     
    journeyoftheanimals, Nov 30, 2007 IP
  7. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Then you probably need to use:
    $mybb->user['username']
    and not $mybbuser[username]

    But take my version from above, with ".", that should work 100% just replace it with $mybb->user['username']

    Btw. rep+ button is in the top right corner :p

     
    hogan_h, Nov 30, 2007 IP
    journeyoftheanimals likes this.
  8. Xexi

    Xexi Well-Known Member

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    100
    #8
    There could be a few solutions why this is not working. As I don't know how your script is setup, here are a few solutions:

    First remember to put array outputs inside { and } (left brace/left curly bracket and right brace/right curly bracket) when placed inside quotations or apostrophes. In this case you are using quotations in your echo function.
    Array examples: $mybb->user['uid'] or $mybbuser['username']

    echo "Hey, {$mybb->username]}.<br> Thanks for logging in."; //If you unintentionally changed $mybb to $mybbuser
    echo "Hey, {$mybbuser['username']}.<br> Thanks for logging in."; //if you forgot to add the apostrophes

    I highly recommend you try out Nusphere PhpED.
     
    Xexi, Nov 30, 2007 IP
  9. journeyoftheanimals

    journeyoftheanimals Well-Known Member

    Messages:
    339
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #9
    Thank you. I will check out that link. I think I read somewhere that the code
    $mybbuser
    Code (markup):
    changed so I am trying to look into that.
     
    journeyoftheanimals, Nov 30, 2007 IP
  10. journeyoftheanimals

    journeyoftheanimals Well-Known Member

    Messages:
    339
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #10
    OK. I do not expect anyone on here to really care how I got this to work. But incase there is a "mybb" user here that wants to know I figured I would post it.


      // The user is logged in, say Hi
    echo "Hey, $mybbuser[username].<br>
    Thanks for logging in.";
    Code (markup):



      // The user is logged in, say Hi
    echo "Hey, {$mybb->user['username']}.<br>
    Thanks for logging in.";
    Code (markup):
    It was part of a code change with the latest version of mybb.


    Thank you for everyone who replied to this post.
     
    journeyoftheanimals, Nov 30, 2007 IP