未按预期显示产品详细信息


Product details not showing as intended

我在github上找到了这个php项目。香草套装[https://github.com/syndicatefx/vanilla-kit],是一个非常简单的php驱动的动态网站模板,我喜欢干净的文件夹结构,因此决定使用/尝试它。

这是根目录上的索引页,非常简单。它调用用户请求的页面(在文件夹页面中),并用请求的页面名称替换变量$page并显示它

<?php
// Defualt page will always be pages/homepage.html, if not, change this to the name of the file you have created to be the homepage.
$page = 'homepage';
// Get pages based on user input 
if (!empty($_GET['name'])) {
    //Assign a variable to a sanitised version of the data passed in the URL
    $tmp_page = basename($_GET['name']); 
    //If the file exists, update $page
    if (file_exists("pages/{$tmp_page}.php")) 
        $page = $tmp_page;
    //If the file does not exist, include notfound page and exit  
    elseif(!file_exists($tmp_page)){
        include 'pages/notfound.php';
        exit;
        }
    }
// Include $page (declared default)
include ("pages/$page.php");
?>

作为主页的默认页面从产品表中提取产品并进行显示

<?php 
// Edit this page's title, description and keywords for SEO
$pagetitle = 'Welcome';
$pagedescription = 'description goes here...';
$pagekeywords = 'keywords,go,here';
// Add a class to body for more CSS power
$bodyclass = 'home';
// Do Not Remove
include 'inc/header.php'; 
?>
<?php 
$dbquery = "SELECT * FROM lbtbl_products"; 
$productresult = $dbconnect->query($dbquery);
if ($productresult->num_rows > 0) {
while($row = $productresult->fetch_assoc()) { ?>
<div class="prod-cnt prod-box">
<form method="post" action="cartupdate.php">
<h3 class="prod-title">
<a href="productdetail.php?id=<?php echo $row['lbproductId'];?>"><?php echo $row["lbproductName"]; ?></a>
</h3>
<p><?php echo $row["lbproductDescription"];?></p>
<div class="price-cnt">
<div class="prod-price"><img src="images/common/rupees.png" width="7" height="10"/> <?php echo $row["lbproductPrice"];?></div>
Qty <input type="text" name="product_qty" value="1" size="3" />
<button class="add_to_cart">Add To Cart</button>
<input type="hidden" name="product_code" value="<?php echo $row["lbproductSku"];?>" />
<input type="hidden" name="type" value="add" />
<input type="hidden" name="return_url" value="<?php echo $current_url;?>" />
</div>
</form>
</div>
<?php }
} else {
echo "0 results";
}
$dbconnect->close(); ?>
<?php include 'inc/footer.php'; ?> 

到目前为止一切都很好。

现在,为了显示产品详细信息,我有一个页面名称productdetails.php,它与所有其他页面一样保存在pages目录中。"主页"上查看产品详细信息的链接是

<a href="productdetail.php?id=<?php echo $row['lbproductId'];?>"><?php echo $row["lbproductName"]; ?></a>

但是一旦点击,就会显示404未找到的页面。但是,如果我将productdetails.php页面移到根目录,它就可以工作了。有人能帮助/建议解决方案吗。我最好的猜测是,这与注释//基于用户输入获取页面后的index.php代码有关。

尝试并共享结果。

<a href="?name=productdetail.php&id=<?php echo $row['lbproductId'];?>"><?php echo $row["lbproductName"]; ?></a>

在产品详细信息页面中,您应该使用$_GET['id']运行选择查询。它可能会起作用,尝试并分享结果。