Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: Parse error:

  1. #1
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts

    Parse error:

    I get this error when I go to /add/

    PHP Code:
    if ($_GET['add'] == "news"){ 
    I have this in my code and if it's "?add=news" then whatever but when I got /add/ it displays this error:
    Notice: Undefined index: add in **/add/index.php on line 27

    When I try to add isset()
    PHP Code:
    if (isset($_GET['add'] == "news")){ 
    with this error
    Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')' in /**/add/index.php on line 27

    There must a be a simple solution and reason for this?

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    ...It should be
    if(isset($_GET["add"] )){ instead

    There should be no comparison inside the isset function

    See if it helps

  • Users who have thanked rangana for this post:

    Dat (02-16-2008)

  • #3
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Then am I using this correctly?:

    PHP Code:
    if(isset($_GET['add'] )) {

        if(
    $_GET['add'] == "news") {
           echo 
    'news';
        }elseif(
    $_GET['add'] == "anime") {
           echo 
    'anime';
        }elseif(
    $_GET['add'] == "manga") {
           echo 
    'manga';

    } else {
        echo 
    'Select something to do!';

    It work's but is this the only approach, I mean have to say that it looks really irregular to me... It could be because of my inexperience but it look un pro-like?, unorganized?

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    It's fine!...nothing could cause a harm

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You're missing a closing brace:
    PHP Code:
    if(isset($_GET['add'] )) {

        if(
    $_GET['add'] == "news") {
           echo 
    'news';
        }elseif(
    $_GET['add'] == "anime") {
           echo 
    'anime';
        }elseif(
    $_GET['add'] == "manga") {
           echo 
    'manga';
        } 
    // here
    } else {
        echo 
    'Select something to do!';

    Also, if you're making multiple comparisons of the same value it's generally preferable to use the switch() statement:
    PHP Code:
    if(isset($_GET['add']))
    {
        switch(
    $_GET['add'])
        {
            case 
    'news':
                echo 
    'news';
            break;
            
            case 
    'anime':
                echo 
    'anime';
            break;
            
            case 
    'manga':
                echo 
    'manga';
            break;
            
            default:
                
    // this is optional
            
    break;
        }
    }
    else
    {
        echo 
    'Select something to do!';


  • The Following 2 Users Say Thank You to Inigoesdr For This Useful Post:

    Dat (02-16-2008), oesxyl (02-16-2008)

  • #6
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    I guess. How would you approach this type of situation. Would you use the same kind of code I'm using?

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    He posted an example of what should be used.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Sorry, I posted 20 seconds after that, thank you. I used that approach, and it work's like a dream.


  •  

    Posting Permissions

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