多个$ _GET函数不起作用

时间:2013-02-23 20:30:40

标签: php html get

我一直在设计一些网站。我一直在尝试使用多个if(isset($ _ GET ['type'])=='page'){}等等函数。他们似乎没有工作可以有人开导我吗?

<?php
    if(isset($_GET['type']) == 'all') {
    // View All Pages Title
    echo '<h3>View All Pages</h3>';

        if($control1 == 'all') {
            echo '<table width="100%" border="0">';
            echo '<tr>';
            echo '<th scope="col">Page Name</th>';
            echo '<th scope="col">Time Created</th>';
            echo '<th scope="col">View</th>';
            echo '<th scope="col">Edit</th>';
            echo '<th scope="col">Delete</th>';
            echo '</tr>';                 
            $qry=mysql_query("SELECT * FROM page", $con);
            if(!$qry) {
                die("Query Failed: ". mysql_error());
        }
        while($row=mysql_fetch_array($qry)) {
            echo '<tr>';
            echo '<td height="38">'.$row['page_title'].'</td>';
            echo '<td>'.$row['page_updated'].'</td>';
            echo '<td><a href="page.php?view=page&page='.$row['page_link'].'">View</a></td>';
            echo '<td><a href="page.php?edit='.$row['page_link'].'">Edit</td>';
            echo '<td><a href="page.php?delete='.$row['id'].'">Delete</td>';
            echo '</tr>';
        }     
        echo '</table>';
    }
    else {
        echo "<p>You can't view all the pages. Your Account does not hold the correct priorirty</p>";   
    }
}
elseif(isset($_GET['type']) == 'add') {
    // Add New Page Title
    echo '<h3>Add New Page</h3>';
        if($control1 == 'all') {
            echo '<p><a href="pages.php?type=add&add=control" target="new">Click Here to add a new page</a></p>';
    }
    else {
        echo "<p>You can't add new pages. Your Account does not hold the correct priority.</p>";
    }
}
elseif(isset($_GET['type']) == 'edit') {
    // Edit Pages Title
    echo '<h3>Edit a Page</h3>';
        if($control1 == 'all') {
            echo '<table width="100%" border="0">';
            echo '<tr>';
            echo '<th scope="col">Page Name</th>';
            echo '<th scope="col">Edit</th>';
            echo '</tr>';
            $qry=mysql_query("SELECT * FROM page", $con);
                if(!$qry) {
                    die("Query Failed: ". mysql_error());
            }
            while($row=mysql_fetch_array($qry)) {
                echo '<tr>';
                echo '<td height="38">'.$row['page_title'].'</td>';
                echo '<td><a href="page.php?edit='.$row['page_link'].'">Edit</td>';
                echo '</tr>';
            }
            echo '</table>';
        }
        else {
            echo "<p>You can't edit any pages. Your Account does not hold the correct priority </p>";
        }
    }
?>

这是确切的代码。如果您能解释一下我可以做些什么来修复它,我们将不胜感激!提前谢谢!

5 个答案:

答案 0 :(得分:2)

isset($_GET['type'])返回一个布尔值,因此如果将该布尔值与任何不相同的布尔值(isset($_GET['type']) == 'all')进行比较,则返回false。

你应该做

if ( isset($_GET['type']) && $_GET['type'] == 'all' ) { // code }

答案 1 :(得分:0)

必须像这样

if(isset($_GET['type']) && $_GET['type'] == 'page')

答案 2 :(得分:0)

isset返回布尔值:true或false。因此你的代码:

if(isset($_GET['type']) == 'page')

不起作用。您可以这样更改:

if(isset($_GET['type']) and $_GET['type'] == 'page')

答案 3 :(得分:0)

问题是isset()函数仅返回TRUEFALSE,并且您将其与字符串进行比较。只需使用它:

if (isset($_GET['type']) {
   if ($_GET['type'] == 'page') {
      //...
   } elseif($_GET['type'] == 'add') {
      //and so on...
   }
}

最好将isset测试放在开头,这样就不会在每个if语句中进行检查。

答案 4 :(得分:0)

正如我所看到的,isset()返回一个布尔值(true / false),你要与“all”,“add”等进行比较。那不是你想要的。

你可以这样做:

if (isset($_GET['type']) && $_GET['type'] == "all") {
    #your code here
}