使用$ _GET ['id']从路径获取ID的问题(Angular Site)

时间:2016-12-02 23:24:37

标签: php angularjs angular-routing

我有一个错误,它不会将ID发送到带有$ _GET ['id']的页面(#/ post?id = 1)

我收到以下错误:

Notice: Undefined index: id in D:\xampp\htdocs\ls\includes\post.php on line 3

请参阅GitHub:https://github.com/liamstewart23/LSPortfolio

我有一个博客页面。列表博客帖子工作正常。

问题是当我尝试将ID发送到我的帖子页面时:

blog.php的

<?php
require_once("../admin/phpscripts/init.php");
$tbl="tbl_blog";
$getPosts = getAll($tbl);
//echo $getPosts;
?>
<section id="blog">
<h2 class="hidden">Blog Posts</h2>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-10 col-md-offset-1"><h2>Blog</h2></div>
<div class="col-xs-12 col-sm-12 col-md-10 col-md-offset-1"><h3>My thoughts, beliefs and complaints.</h3></div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-sm-offset-0 col-md-8 col-md-offset-2" id="blog-posts">
<?php
if(!is_string($getPosts)){
while($row = mysqli_fetch_array($getPosts)){
        echo "<h1>{$row['b_title']}</h1>";
        echo "<span>Posted: {$row['b_date']} by {$row['b_author']}</span><br><br>";
        echo "<a href=\"#/post?id={$row['b_id']}\">Read Post...</a><br><br>";
        }
        } else {
        //echo "nope...";
        }
        ?>
    </div>
</div>

post.php中

<?php
require_once("../admin/phpscripts/init.php");
echo $_GET["id"];   
echo "hello";
?>

Read.php(使用require_once在init.php中调用)

<?php
function getAll($tbl){
    require_once("config.php");
    $queryAll = "SELECT * FROM {$tbl}";
    //echo $queryAll;
    $runAll = mysqli_query($link, $queryAll);
    if($runAll) {
        return $runAll;
    } else {
        $error = "There was an error accessing this information. Shoot me an email at me@lstew.com";
        return $error;
    }

    mysqli_close($link); //want to make sure that it is terminated, do not want anything accessible
} 


function getPost($id, $tbl, $col) {
    require_once("config.php");
    $querySingle = "SELECT * FROM {$tbl} WHERE {$col}={$id}";
    //echo $querySingle;
    $runSingle = mysqli_query($link, $querySingle);
    if($runSingle) {
        return $runSingle;
    }
    else {
        $error = "This is not the movie you are looking for...";
        return $error;
    }
    mysqli_close($link);
}
?>

0 个答案:

没有答案