Coding Error in PHP

Hi Folks,
    I have a simple page that is driving me nuts. The purpose of the page is to display message, which it does and then take the user back to their respective menus.
The page is receiving and displaying my $_SESSION variable correctly. I have verified that it does with the echo statement.
So I know that is not the problem.
The problem seems to be the way I constructed the remaining two echo statements to reroute the user back to their respective menus.
The page will display with the button, but when I click on the button, nothing happens...booo!
Can someone be as so kind as to point out my error? I have posted the coding below...
Thank you




<?php
  include("Includes/session.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

 <html>
    <head>
     <title>Dogs</title>
     <link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
    </head>
   
    <body class="bodybg">
          <table class="meologo" align="center"><tr><td>
           <img src="/images/Dog_logo_lg.jpg" alt="Dogs">
        </td></tr></table>
        <table class="msginfo" align="center"><tr><td>This option is not available yet.</td></tr>
        <tr><td>&nbsp;</td></tr>
     
            <?php
               
 
           //  echo $_SESSION['UserType'];
               
             if ($_SESSION['UserType'] == "A")
             
                    echo "<tr><td><button onclick='amenu.php'>Return to Menu</button></td></tr>";
                 
               if ($_SESSION['UserType'] == "S")
                 echo "<tr><td><button onclick='smenu.php'>Return to Menu</button></td></tr>";
 
             
             ?>


            </table>
    </body>
</html>
OverthereAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
<button onclick='smenu.php'>Return to Menu</button> does not tranfer you to another page.  'onclick' is expecting a javascript function to do anything but all you are giving it is a relative URL.  The more common way would be to use a normal link like <a href='smenu.php'>Return to Menu</a> .

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
F PCommented:
Onclick is meant to house a JavaScript action, and not simply a URL. You'd need to put:

<?php
               
 
           //  echo $_SESSION['UserType'];
                
             if ($_SESSION['UserType'] == "A")
              
                    echo "<tr><td><button onclick='window.location='/amenu.php'>Return to Menu</button></td></tr>";  // make sure the amenu is in the root, or change that relative path
                 
               if ($_SESSION['UserType'] == "S")
                 echo "<tr><td><button onclick='window.location='/smenu.php'>Return to Menu</button></td></tr>"; // make sure the smenu is in the root, or change that relative path
  
             
             ?>

Open in new window

F PCommented:
On a side note not about the resolution. Don't echo out two lines of code the exact same except for 1 letter. Make that if statement populate a single variable, echo out that code once with the variable in the place of the current amenu or smenu you have now. Much cleaner, and if you need to change something, it's only one place to do it. You could even concatenate a ternary conditional...
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Ray PaseurCommented:
If you're new to PHP and web application development, this article can help you find some dependable learning resources.  Before you start with PHP, make sure you are proficient in HTML, CSS and JavaScript.  Otherwise you may waste your time in areas that overlap the technologies.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
F PCommented:
onclick = script [CT]
The onclick event occurs when the pointing device button is clicked over an element.

Script data ( %Script; in the DTD) can be the content of the SCRIPT element and the value of intrinsic event attributes. User agents must not evaluate script data as HTML markup but instead must pass it on as data to a script engine.

The case-sensitivity of script data depends on the scripting language.

http://www.w3.org/TR/html4/interact/scripts.html#adef-onclick

http://www.w3.org/TR/html4/types.html#type-script
OverthereAuthor Commented:
Thank you folks for answering. The client does not like links, so it has to be a button.
Otherwise, links would work!
 I was pretty sure that I would to have use form tags and  post back statements if I was using this structure...so below is how I changed the code and it works as it should now.
All  of you provide good information that was educational etc.,  so I am splitting the points, if this is not agreeable, please let me know...:)

<?php
  include("Includes/session.php");

   if (isset($_POST['submit']))
      {
          if ($_SESSION['UserType'] =="S")
             {
                header ("Location: smenu.php");
           } else {
                header ("Location: amenu.php");
           }
     }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

 <html>
    <head>
     <title>Dogs</title>
     <link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
    </head>
   
    <body class="bodybg">
            <table class="meologo" align="center">
                   <tr><td>
                         <img src="/images/Dog_logo_lg.jpg" alt="Dogs">        
                  </td></tr>
         </table>
       
         <form action="notavailable.php" method="post">
 
             <table class="msginfo" align="center">
                         <tr><td>This option is not available yet.</td></tr>
               
                     <tr><td><input type="submit" name="submit" value="Return" src="images/Return.jpg"/>

                      <tr><td>&nbsp;</td></tr>
            </table>

        </form>

    </body>
</html>
OverthereAuthor Commented:
Thank you folks.  Your responses were easy to understand, appreciated and the links to knowledge articles were great!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.