[英]How to go product details page from product page
I'm trying with a E-Commerce website. 我正在尝试使用电子商务网站。 But I'm having trouble.
但是我有麻烦了。 I want that when I click in the view details link of a product, the details of the product will be shown on the
product_details.php
page. 我希望当我单击产品的查看详细信息链接时,该产品的详细信息将显示在
product_details.php
页面上。 But I can't transfer the product id to the product_details.php
page. 但是我无法将产品ID转移到
product_details.php
页面。 My code is here... 我的代码在这里...
<?php
include ("include/header.php");
?>
<?php
mysql_connect("localhost", "root", "") or die("problem with Connection");
mysql_select_db("finalproject");
$per_page = 3;
$pages_query = mysql_query("SELECT COUNT('product_id') FROM product");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset ($_GET['page'])) ? (int) $_GET['page'] : 1;
$start = ($page - 1 ) * $per_page;
$query = mysql_query("SELECT * FROM product LIMIT $start,$per_page");
while ($query_row = mysql_fetch_assoc($query))
{
echo "<b>$query_row[product_name]</b><br>";
echo "<b>Brand : </b> $query_row[product_brand] <br>";
echo "<b>Description : </b> $query_row[description] <br>";;
echo "<b>Price : </b> $query_row[price] <br>";
echo ('<a href="product_details.php? id='.$query_row['product_id'].'">View details</a><br><br>') ;
?>
<form action="product_details.php?productId=<?php echo $row['product_id'];? >>" method="post">
<?php
}
$prev = $page - 1;
$next = $page + 1;
if (!($page <=1))
{
echo "<a href='buyproduct.php?page=$prev'>Prev</a> ";
}
if($pages >= 1)
{
for ($x=1; $x<=$pages; $x++)
{
echo ($x == $page) ? '<b><a href="?page='.$x.' ">'.$x.'</a></b> ' : '<a href="?page='.$x.' ">'.$x.'</a> ';
}
}
if (!($page >= $pages))
{
echo "<a href='buyproduct.php?page=$next'>Next</a> ";
}
?>
<?php
include ("include/footer.php");
?>
and my product_details.php
is 而我的
product_details.php
是
<?php
include ("include/header.php");
?>
<?php
include ("database.php");
$productId = $_GET['productId'];
$sql = "SELECT * FROM product WHERE product_id = $productId";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<b>$row[product_name]</b><br>";
echo "<b>Brand : </b> $row[product_brand] <br>";
echo "<b>Description : </b> $row[description] <br>";;
echo "<b>Price : </b> $row[price] <br><br>";
"<br>";
}
?>
<?php
include ("include/footer.php");
?>
and when running in the browser when clicking to viw details in product_details.php
the error is : 当在浏览器中运行并单击
product_details.php
的viw详细信息时,错误为:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\\xampp\\htdocs\\project2\\product_details.php on line 17
警告:mysql_fetch_array()期望参数1为资源,在第17行的C:\\ xampp \\ htdocs \\ project2 \\ product_details.php中给出布尔值
Now what can I do.... 现在我该怎么办...
In product_details.php the syntax of sql query is incorrect. 在product_details.php中,sql查询的语法不正确。 Put $productId in quote.
将$ productId放在引号中。
The query sholu look like this.. 查询应该像这样..
$sql = "SELECT * FROM product WHERE product_id = '$productId'";
Hope this will help.. 希望这会有所帮助..
You have an error in your html... 您的html中有错误...
<form action="product_details.php?productId=<?php echo $row['product_id'];? >>" method="post">
Should be... 应该...
<form action="product_details.php?productId=<?php echo $row['product_id'];?>" method="post">
Your sending an extra ">" with your product id 您额外发送了一个带有商品ID的“>”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.