Jump to content

pegastep

New Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by pegastep

  1. I tried it and that worked, thank you. However, I'd still like to be able to get to the bottom of why the if/else isn't working.

     

     

     

    So I'd type something like

    if ("reagan" == $_GET['show'])
    

    ?

     

    Using the code I typed up there, the page will work if I go right to lab.php?show=reagan or any of the other values. However, if I just go to lab.php, I get an "Unidentified Index: show" error on all of the lines where I used the $_GET['show']. Is there any way I can fix this?

  2. All I want to say

    switch($_GET['show']) {
    case 'reagan':
    code .....
    }

     

    I tried it and that worked, thank you. However, I'd still like to be able to get to the bottom of why the if/else isn't working.

     

    You need to use $_GET['show'] to access the variable from the URL. Being able to use $show directly is an old "feature" called register_globals which has since been removed as it generally causes more harm than good.

     

    Check out the manual page on superglobals for some details about what variables to use and when.

     

    So I'd type something like

    if ("reagan" == $_GET['show'])
    

    ?

  3. Excuse my unintelligence, I'm fairly new to php, but I'm working on writing a page for a class and I'm having trouble getting it to work. Taking out all the unnecessary text, here's my code:

     

    <?php
    if(!isset($show))
    {
    $show="";
    }
    ?>
    <html><head><title>Lab</title></head>
    <body>
    <table>
    <tr><td>
    <h3>Menu</h3>
    <ul>
    <li><a href="lab.php?show=reagan">Ronald Reagan</a></li>
    <li><a href="lab.php?show=kennedy">John F. Kennedy</a></li>
    <li><a href="lab.php?show=roosevelt">Franklin Roosevelt</a></li>
    <li><a href="lab.php?show=lincoln">Abraham Lincoln</a></li></ul>
    </td><td class="content">
    <?php
    if ("reagan"== $show)
    {
    echo "<h3 class=\"topHeading\">Ronald Reagan</h3><br />";
    echo "<img src=\"reagan.gif\" align=\"left\" /><p>Text1</p>";
    }
    else if ("kennedy" == $show)
    {
    echo "<h3 class=\"topHeading\">John F. Kennedy</h3><br />";
    echo "<img src=\"kennedy.gif\" align=\"left\" /><p>Text2</p>";
    }
    else if ("roosevelt" == $show)
    {
    echo "<h3 class=\"topHeading\">Franklin Roosevelt</h3><br />";
    echo "<img src=\"roosevelt.gif\" align=\"left\" /><p>Text3</p>";
    }
    else if ("lincoln" == $show)
    {
    echo "<h3 class=\"topHeading\">Abraham Lincoln</h3><br />";
    echo "<img src=\"lincoln.gif\" align=\"left\" /><p>Text4</p>";
    }
    else
    {
    echo "<center><h1>Presidential Quotes</h1><br /><h3>Text5</h3>
    ?>
    </td></tr>
    </table>
    </body>
    </html>
    

    The way this is supposed to operate is that the page displays "Text5" until one of the links is clicked. The link should assign a value to $show, and then the content cell will display Text1, Text2, Text3, or Text4, depending on which link was clicked. The only problem is, the content cell still shows "Text5," regardless of which links I click. I suspect this is a problem with passing the values via the link, but it could very well be something else that I'm missing. I've gone through this and I can't seem to find the problem. Does anybody see any particualrily noticable errors? Thank you for taking the time to read this.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.