sn1984
sn1984

Reputation: 95

Developing Web Applications

I am learning how to develop web applications using php. I am trying to get this contact form to come up when you click the contact link but nothing happens. I have been over and over the pages and I do not see why it does not work.

Here is the page:

// Determine what page to display:
switch ($p) {

    case 'about':
        $page = 'about.inc.php';
        $page_title = 'About This Site';
        break;

    case 'this':
        $page = 'this.inc.php';
        $page_title = 'This is Another Page.';
        break;

    case 'that':
        $page = 'that.inc.php';
        $page_title = 'That is Also a Page.';
        break;

    case 'contact':
        $page = 'contact.inc.php';
        $page_title = 'Contact Us';
        break;

    case 'search':
        $page = 'search.inc.php';
        $page_title = 'Search Results';
        break;

    // Default is to include the main page.
    default:
        $page = 'main.inc.php';
        $page_title = 'Site Home Page';
        break;

} // End of main switch.

// Make sure the file exists:
if (!file_exists('./modules/' . $page)) {
    $page = 'main.inc.php';
    $page_title = 'Site Home Page';
}

And here is the last one:

    <div id="navigation">
        <ul id="navlist">
            <li><a href="index.php">Home</a></li>
            <li><a href="index.php?p=about">About Us</a></li>
            <li><a href="index.php?p=this">This</a></li>
            <li><a href="index.php?p=that">That</a></li>
            <li><a href="index.php?p=contact">Contact</a></li>
<li><p><strong>A tiny little service announcement.</strong><br/>Please contact us with any questions. </p></li>
        </ul>

The error I am getting is when you click on the link that says contact in the navigation system does not do anything. It is suppose to go to the contact.inc.php so the form shows and the person can fill out. I have been over the code many times and I am not seeing why it will not go over to the contact.inc.php.

Edit: I even tried to change the index.php?p=contact to contact.inc.php and nothing happens either.

Edit: Here is a link to my page. Now if you click on the contact you will see it does not take you to the contact page.http://www.elinkswap.com/snorris/index.php

Upvotes: 0

Views: 183

Answers (2)

Lars Strojny
Lars Strojny

Reputation: 665

You are trying to use Register Globals which is highly discouraged. Instead, access the GET variable explicitly by using switch ($_GET['p']). Additionally check for the existence of $_GET['p'] before using isset().

Upvotes: 1

student
student

Reputation: 213

Try to use debugging tools and place breakpoints at possible areas, if you need to do manual debugging, you could echo a message and die try replacing the code below:

// Make sure the file exists:
if (!file_exists('./modules/' . $page)) {
  $page = 'main.inc.php';
  $page_title = 'Site Home Page';
   echo "$page file didnt exist";
   die();
}

if you you see the file didn't exist, means you know your ./modules/$page didn't exist and the $page is overwritten with main.inc.php, therefore you have to make sure your folders and files are correctly placed.

Upvotes: 0

Related Questions