我正在学习如何使用php开发Web应用程序。当我点击联系链接但没有任何反应时,我试图让这个联系表单出现。我一直在翻页,我不明白为什么它不起作用。
以下是页面:
// 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';
}
这是最后一个:
<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>
我得到的错误是当您点击导航系统中的联系人没有做任何事情的链接时。假设要转到contact.inc.php,以便表单显示并且该人可以填写。我已多次查看代码,但我不知道为什么它不会转到contact.inc.php。
编辑:我甚至试图将index.php?p = contact更改为contact.inc.php,但也没有任何反应。
编辑:这是指向我的页面的链接。现在,如果您点击该联系人,您将看到它不会将您带到联系页面.http://www.elinkswap.com/snorris/index.php
答案 0 :(得分:1)
您正在尝试使用Register Globals,这是非常气馁的。相反,使用switch($_GET['p']
)显式访问GET变量。在使用$_GET['p']
之前,请检查是否存在isset()
。
答案 1 :(得分:0)
尝试使用调试工具并在可能的区域放置断点,如果需要进行手动调试,可以回显消息并尝试替换以下代码:
// 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();
}
如果您看到该文件不存在,则表示您知道您的./modules/$page不存在 $ page被main.inc.php 覆盖,因此您必须确保正确放置文件夹和文件。