“Index.php?网页”功能不正常

时间:2014-10-05 00:38:11

标签: php post get isset

所以我正在尝试访问我网站中的某个网页。

在我的索引中,我使用isset($ _ GET()参数来访问另一个页面。我的index.php代码如下:

<!DOCTYPE html>
<html>
<head>
    <?php require ("includes/database.php"); ?>
    <title>Offstreams Admin Panel</title>
    <link rel="stylesheet" type="text/css" href="styles/admin_body.css" />
    <link rel="stylesheet" type="text/css" href="styles/admin_header.css" />
    <link rel="stylesheet" type="text/css" href="styles/admin_footer.css" />
    <link rel="stylesheet" type="text/css" href="styles/admin_postspace.css" />
</head>
<body>
    <header>
        <!--Header Info Here -->
    </header>
    <div class="wrapper">
        <div class="sidebar">
            <ul>
                <li><a href="index.php?post_new_band">Post New Band</a></li>
            </ul>
        </div>
        <article>
            <?php
                if (isset($_GET['post_new_band'])){
                    require ("includes/post_new_band.php");

                    echo "Page accessed";
                } else {
                    echo "Page not accessible."; 
                }       
            ?>
        </article>
    </div>
</body>
</html>

当“index.php?page”不存在时,我有echo页面不可用。但是当它确实存在时,例如“index.php?post_new_band”(下面的代码),没有发布任何内容。服务器和数据库工作,这是肯定的。 MySQL不是问题,因为我试图让html工作。

“post_new_band.php”的代码:

<!DOCTYPE html>
<html>
<head>
    <!-- Head Info Goes Here -->
</head>
<body>
   <h1>Insert New Band</h1>
       <form action='index.php?post_new_band' method='post'>
           <b>Insert New Band</b><input type='text' name='band_name' />
           <b>Insert Band Origin</b><input type='text' name='band_origin' />
           <input type='submit' name='insert_band' value='Add Band' />
       </form>

   <?php
       if (isset($_POST['post_new_band'])){
           $band_name = $_POST['band_name'];

           if($band_name==''){
               echo "<script>alert ('Please Insert Band Name')</script>";
               echo "<script>window.open('index.php?post_new_band','_self')</script>"
           } else {

               $insert_band_name = "insert into Band  (band_name) values ('$band_name')";

               $run_band_name = mysql_query("$insert_band_name");

               echo "<script>alert ('New Category Added')</script>";
               echo "<script>window.open('index.php?post_new_band','_self')</script>"
           }
       }
   ?>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

您只能使用一次请求密钥 - 因此请勿在同一请求中使用$_GET['post_new_band']$_POST['post_new_band']。更改其中一个键。

答案 1 :(得分:0)

这非常愚蠢,但事实证明它是一个涉及分号的语法错误。 *啪的一声。

相关问题