SitePoint Sponsor

User Tag List

Results 1 to 24 of 24

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Errors (noobie needs help! :( )

    hi there! i am trying to pass some values through multiple pages here
    and i am running into problems with code Clam heelped me with :P

    PHP Code:
    <?PHP 
    switch ($_GET['navigation']) { 
    case 
    'one'
    $file 'menu1.php'
    break; 
    case 
    'two'
    $file 'menu2.php'
    break; 
    case 
    'three'
    $file 'menu3.php'
    break;
    case 
    'four'
    $file 'menu4.php'
    break;

    default: 
    $file 'menu1.php'
    }  
    ?>
    it's saying something about T_CASE and unexpected "}"
    sorry i'm so so new to PHP, and yes! i did buy a couple books

    my links are as follows:

    <a href="testfile.php?navmenu=one">FIRST CHOICE</a> <br />
    <a href="testfile.php?navmenu=two">SECOND CHOICE</a> <br />

    etc
    thanks in advance!
    jamie

  2. #2
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your error isn't in that code. What line does it say the error occurs? Post your code before, at and and after that line.

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the error says Line 11

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?PHP 
    switch ($_GET['navmenu']) { 
    ****case 
    'one'
    ********
    $file 'menu1.php'
    ********break; 
    ****case 
    'two'
    ********
    $file 'menu2.php'
    ********break; 
        case 
    'three'
    ********
    $file 'menu3.php'
    ********break;
        case 
    'four'
    ********
    $file 'menu4.php'
    ********break;

    ****
    // etc... 
    ****default: 
    ********
    // in case no match or no value 
    ********$file 'menu1.php'
    }  
    ?>

    <a href="testfile.php?navmenu=one">FIRST CHOICE</a> <br />
    <a href="testfile.php?navmenu=two">SECOND CHOICE</a> <br />
    <a href="testfile.php?navmenu=three">THIRD CHOICE</a> <br />
    <a href="testfile.php?navmenu=four">FOURRTH CHOICE</a> <br />

    </body>
    </html>
    Parse error: parse error, unexpected T_STRING, expecting T_CASE or T_DEFAULT or '}' in /home/nitionde/public_html/test_php/index.php on line 11

    thanks for you quick reply btw!

  4. #4
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is the use of the stars in this code?


    I believe that's your problem..

    try it the standard way


    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?PHP
    switch ($_GET['navmenu']) {

    case 
    'one':
    $file 'menu1.php';
    break;


    case 
    'two':
    $file 'menu2.php';
    break;


    case 
    'three':
    $file 'menu3.php';
    break;


    case 
    'four':
    $file 'menu4.php';
    break;


    default:
    $file 'menu1.php';
    break;

    }  
    ?>

    <a href="testfile.php?navmenu=one">FIRST CHOICE</a> <br />
    <a href="testfile.php?navmenu=two">SECOND CHOICE</a> <br />
    <a href="testfile.php?navmenu=three">THIRD CHOICE</a> <br />
    <a href="testfile.php?navmenu=four">FOURRTH CHOICE</a> <br />

    </body>
    </html>

    you forgot the first dollar sign
    you also forgot the last break;


    the code above works

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh!
    well the stars aren't in there
    when ever i use the PHP tag thing in here, it adds stars to the spaces
    or its possible some weird char's got in the code?
    well ill try that!
    thanks!

  6. #6
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh !
    that was the problem! thank you
    of course i have more problems, but at least thats out of the way!
    thanks

    is there any problem with my links? do i need single quotations or do they need to be in PHP tags?

  7. #7
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got the first code wrong

    I edited my post, that one works (I tried it on my server) =]

  8. #8
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you're welcome to post the problems in this thread and I'll help you solve them (I'll be on all night, haha)

  9. #9
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh thank you!
    you are so kind!

    well, it seams my links aren't working, the Error, is :

    Warning: main(): Failed opening '' for inclusion (include_path='.:/usr/local/lib/php') in /home/nitionde/public_html/test_php/testfile.php on line 10

    line 10 is



    PHP Code:
    <?php include("$file"); ?>
    even when i remove the quotes i get an error

    so

    ($file)

  10. #10
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, first thing is the quotes arn't needed.

    So

    PHP Code:

    <?php include($file); ?>

    is fine.


    And what is $file declared as?

  11. #11
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well $file should be what i was passing through the link correct?
    so
    <a href="testfile.php?navmenu=one">FIRST CHOICE</a>

    should be one, which would be "menu1.php"

    although, it is saying it's failing to open

  12. #12
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's saying it's failing to open because $file doesn't exist


    is $file

    $file = '<a href="testfile.php?navmenu=one">FIRST CHOICE</a>';



    ?


    if so, change it to


    $file = 'testfile.php?navmenu=one';

  13. #13
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well $file should be $file = 'menu1.php';

    case 'one':
    $file = 'menu1.php';
    break;

    so i was trying to pass "one" through the link

    am i going about this tthe wrrong way?

  14. #14
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah I see


    does menu1.php exist on your server?
    if not, there's your problem

  15. #15
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep, looks like it
    i just re-uploaded, just incase there was a transfer error
    still the same

  16. #16
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you sure it's in the same directory as the file with

    include($file);


    wrote in it?



    if so, then please post the whole code


    if not, then move menu1 and all the other menu# files into the same directory as the file with include($file); wrote in it in

  17. #17
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep, all in the same dir.
    heres a zip with all the files! not much too them really :P
    thanks for everything so far!
    link should work

    PHPFILES ZIP

    if not
    it's http://www.smilesleepy.com/php_problem.zip

    and if you don't want to download heres all the code for the files

    INDEX
    PHP Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?PHP 
    switch ($_GET['navmenu']) { 

    case 
    'one'
    $file 'menu1.php'
    break; 

    case 
    'two'
    $file 'menu2.php'
    break; 


    case 
    'three'
    $file 'menu3.php'
    break; 


    case 
    'four'
    $file 'menu4.php'
    break; 


    default: 
    $file 'menu1.php'
    break; 
    }

    ?> 

    <a href="testfile.php?navmenu=one">FIRST CHOICE</a> <br />
    <a href="testfile.php?navmenu=two">SECOND CHOICE</a> <br />
    <a href="testfile.php?navmenu=three">THIRD CHOICE</a> <br />
    <a href="testfile.php?navmenu=four">FOURRTH CHOICE</a> <br />

    </body>
    </html>
    TESTFILE
    PHP Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>

    <?php include($file); ?>

    </body>
    </html>
    and the menu#.php files contain simple HTML to test

    PHP Code:
    one <br /> one 

  18. #18
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In test file you aren't defining $file. If you put your menu code above your php include it will work.

    PHP Code:
    <?PHP 
    switch ($_GET['navmenu']) { 

    case 
    'one'
    $file 'menu1.php'
    break; 

    case 
    'two'
    $file 'menu2.php'
    break; 


    case 
    'three'
    $file 'menu3.php'
    break; 


    case 
    'four'
    $file 'menu4.php'
    break; 


    default: 
    $file 'menu1.php'
    break; 


    ?> 

    <?php include($file); ?>

  19. #19
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, I see what the problem is


    include($file); is on another page from the switch thing.


    you need to put the include($file); on the same page as the switch thing, otherwise the PHP parser will not know what to include =]

  20. #20
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    !!
    thank you!
    both of you
    tmapm, thanks for you're help!
    I87, thanks for you're help, and sticking with me

  21. #21
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    np, glad to help =]

  22. #22
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi again!
    well, i'm running into more problems

    i'm trying to pass the navigation choice through the entire site.
    although, when I go beyond the 2nd page, the nav goes to default.

    heres what i got

    PHP Code:
    <?PHP 
    switch ($_GET['menu']) { 

    case 
    'emp'
    $file 'navigation/emp.php';
    $content 'content/emp_content.php'
    $news 'content/emp_news.php';
    break; 

    case 
    'pcp'
    $file 'navigation/pcp.php';
    $content 'content/pcp_content.php';
    $news 'content/pcp_news.php'
    break; 


    case 
    'omp'
    $file 'navigation/omp.php'
    $content 'content/omp_content.php';
    $news 'content/omp_news.php';
    break; 


    case 
    'epp'
    $file 'navigation/epp.php';
    $content 'content/epp_content.php'
    $news 'content/epp_news.php';
    break; 


    default: 
    $file 'navigation/emp.php';
    $content 'content/emp_content.php';
    $news 'content/emp_news.php'
    break; 
    }

    ?>
    and my link contains

    PHP Code:
    <li>  <?PHP Echo "<a class="hide" href=resources.php?menu="$_GET['menu'] .">Resources and Links</a>"?> </li>
    susposedly this will retain the value initially selected?
    heres my error:

    Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/nitionde/public_html/cyanokit_www/navigation/main_nav.php on line 60

    (that is line 60)

    thanks in advance!

  23. #23
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahhh i see

    well, it doesn't seam to like my link CLASS ( "hide")
    when i removed it, all was working properly.
    any ways around this? thanks

  24. #24
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to escape quotes that occur inside of quotes. eg
    PHP Code:
    echo "escape the \"quotes\" or you get parse errors";

    echo 
    'or just use a different "quote" than what you delimited the string with'
    http://www.php.net/manual/en/language.types.string.php


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
  •