1. Paladore - Boopets
    Are you looking for new virtual pet sites or sim games to play?
    Our latest project the virtual pets blog
    Please follow our Rules
    Help us out by Promoting VPL or by Supporting us!
    Feedback needed, Should we add a gallery feature?

Help...?

Discussion in 'Programming General' started by Moonlight, Jun 4, 2011.

  1. Moonlight

    Moonlight Approved Artist
    Web Designer Approved VPL Artist VPL Member

    Reputations:
    2
    Joined:
    Jan 28, 2011
    Messages:
    657
    Likes Received:
    12
    Trophy Points:
    0
    Location:
    Earth
    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:
    <?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:
    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 />';
        }
    }
     
    #1
    support our sponsor and join today
  2. Avalanche

    Avalanche Supporter
    VPL Supporter VPL Member

    Reputations:
    0
    Joined:
    May 30, 2011
    Messages:
    428
    Likes Received:
    82
    Trophy Points:
    0
    Location:
    USA
    It may be possible using the single quotes in the link as well as in the echo is messing something up.

    PHP:
    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.
     
    #2
  3. Noma

    Noma Newish Member
    VPL Member

    Reputations:
    30
    Joined:
    May 24, 2011
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    NJ, USA
    @AvalancheAvalanche'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.
     
    #3
    Last edited by a moderator: Oct 16, 2013
  4. Avalanche

    Avalanche Supporter
    VPL Supporter VPL Member

    Reputations:
    0
    Joined:
    May 30, 2011
    Messages:
    428
    Likes Received:
    82
    Trophy Points:
    0
    Location:
    USA
    @NomaNoma - 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.
     
    #4
    Last edited by a moderator: Oct 16, 2013
  5. Noma

    Noma Newish Member
    VPL Member

    Reputations:
    30
    Joined:
    May 24, 2011
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    NJ, USA
    I wasn't correcting you, just agreeing =]
     
    #5
  6. Moonlight

    Moonlight Approved Artist
    Web Designer Approved VPL Artist VPL Member

    Reputations:
    2
    Joined:
    Jan 28, 2011
    Messages:
    657
    Likes Received:
    12
    Trophy Points:
    0
    Location:
    Earth
    Thank you! It works.
     
    #6
  7. Avalanche

    Avalanche Supporter
    VPL Supporter VPL Member

    Reputations:
    0
    Joined:
    May 30, 2011
    Messages:
    428
    Likes Received:
    82
    Trophy Points:
    0
    Location:
    USA
    #7
    Last edited by a moderator: Oct 16, 2013
  8. jibbles

    jibbles Member
    VPL Member

    Reputations:
    0
    Joined:
    May 10, 2011
    Messages:
    150
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    UK
    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:
    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 />';
        }
    }
     
    #8

Share This Page