Follow us on...
Follow us on Twitter Follow us on Facebook
Register

User Tag List

Results 1 to 8 of 8

Thread: Help...?

  1. #1
    Approved Artist Moonlight's Avatar
    Join Date
    28 Jan 2011
    Location
    Earth
    Posts
    599
    Threads
    67
    Blog Entries
    1

    My Social Networking


    Visit Moonlight's Vimeo Channel

    My User Ranks


    My Reputation

    Help...?

    Anyway, I have a navigation system, and it gives me this error:

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/a1728691/public_html/includes/functions.php on line 21

    The php code to show it is:

    PHP Code:
    <?php navigation(); ?>
    And the function [This is part of a "bigger" part of coding, thus there is no <?php and ?> tags as they come earlier/later on.]:

    PHP Code:
    function navigation()
    {
        if( 
    is_logged_in() ){
            echo 
    '<a href='index.php'>Home</a><br />';
            echo 
    '<a href='news.php'>News</a><br />';
            echo 
    '<a href='logout.php'>Logout</a><br />';    
        } else {
            echo 
    '<a href='index.php'>Home</a><br />';
            echo 
    '<a href='login.php'>Login</a><br />';
            echo 
    '<a href='signup.php'>Signup</a><br />';   
            echo 
    '<a href='news.php'>News</a><br />';
        }


  2. #2
    VPL Supporter Avalanche's Avatar
    Join Date
    30 May 2011
    Location
    USA
    Posts
    428
    Threads
    20
    Blog Entries
    3

    My User Ranks


    My Reputation

    Re: Help...?

    It may be possible using the single quotes in the link as well as in the echo is messing something up.

    PHP Code:
    function navigation() 

        if( 
    is_logged_in() ){ 
            echo 
    '<a href="index.php">Home</a><br />'
            echo 
    '<a href="news.php">News</a><br />'
            echo 
    '<a href="logout.php">Logout</a><br />';     
        } else { 
            echo 
    '<a href="index.php">Home</a><br />'
            echo 
    '<a href="login.php">Login</a><br />'
            echo 
    '<a href="signup.php">Signup</a><br />';    
            echo 
    '<a href="news.php">News</a><br />'
        } 

    Try using the double quotes instead? It won't mess up the HTML. Notice how using the double quotes changes the color of the links. I'm pretty sure that's what is causing your error.

  3. #3
    Newbie Noma's Avatar
    Join Date
    24 May 2011
    Location
    NJ, USA
    Posts
    15
    Threads
    1

    My User Ranks

    My Reputation

    Re: Help...?

    @Avalanche's solution should solve the problem. The reason the links are changing color is your quotes are excluding the links from the original quotations, making them just part of the code and not part of the link reference.

  4. #4
    VPL Supporter Avalanche's Avatar
    Join Date
    30 May 2011
    Location
    USA
    Posts
    428
    Threads
    20
    Blog Entries
    3

    My User Ranks


    My Reputation

    Re: Help...?

    @Noma - yeah that's the more official way of saying it. XD But then when PHP doesn't detect a ';' or ',' after it thinks the echo statement has ended it sends and error.

  5. #5
    Newbie Noma's Avatar
    Join Date
    24 May 2011
    Location
    NJ, USA
    Posts
    15
    Threads
    1

    My User Ranks

    My Reputation

    Re: Help...?

    I wasn't correcting you, just agreeing =]

  6. #6
    Approved Artist Moonlight's Avatar
    Join Date
    28 Jan 2011
    Location
    Earth
    Posts
    599
    Threads
    67
    Blog Entries
    1

    My Social Networking


    Visit Moonlight's Vimeo Channel

    My User Ranks


    My Reputation

    Re: Help...?

    Thank you! It works.

  7. #7
    VPL Supporter Avalanche's Avatar
    Join Date
    30 May 2011
    Location
    USA
    Posts
    428
    Threads
    20
    Blog Entries
    3

    My User Ranks


    My Reputation

    Re: Help...?

    @Noma Oh yeah I know, no worries XD

    @Moonlight YAY!

  8. #8
    Member jibbles's Avatar
    Join Date
    10 May 2011
    Location
    UK
    Posts
    150
    Threads
    6

    My User Ranks

    My Reputation

    Re: Help...?

    An alternative solution is to escape the single quotes. By putting a backslash before the quote mark it tells php that this isn't the end of the string. The backslash itself won't be echo'd.
    PHP Code:
    function navigation()
    {
        if( 
    is_logged_in() ){
            echo 
    '<a href=\'index.php\'>Home</a><br />';
            echo 
    '<a href=\'news.php\'>News</a><br />';
            echo 
    '<a href=\'logout.php\'>Logout</a><br />';    
        } else {
            echo 
    '<a href=\'index.php\'>Home</a><br />';
            echo 
    '<a href=\'login.php\'>Login</a><br />';
            echo 
    '<a href=\'signup.php\'>Signup</a><br />';   
            echo 
    '<a href=\'news.php\'>News</a><br />';
        }


 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •