如何从产品页面转到产品详细信息页面

时间:2015-09-12 06:48:33

标签: php database

我正在尝试使用电子商务网站。但我遇到了麻烦。我希望当我点击产品的查看详细信息链接时,产品的详细信息将显示在product_details.php页面上。但我无法将产品ID转移到product_details.php页面。 我的代码在这里......

<?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");
?>

我的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");
?>

当点击product_details.php中的viw详情时,在浏览器中运行时错误是:

  

警告:mysql_fetch_array()要求参数1为资源,在第17行的C:\ xampp \ htdocs \ project2 \ product_details.php中给出布尔值

现在该怎么办......

2 个答案:

答案 0 :(得分:1)

在product_details.php中,sql查询的语法不正确。把$ productId放在引号中。

查询sholu看起来像这样..

private void addText(View v) {
        // String b = "";
        // b = (String) v.getTag();
        // urdu_word.setText(b);
        if (isEdit == true) {
            String b = "";
            b = (String) v.getTag();
            if (b != null) {
                Log.i("buttonsOnclick", b);
                // adding text in Edittext
                mEt.append(b);
            }
        }
    }

希望这会有所帮助..

答案 1 :(得分:0)

你的html中有错误...

&#13;
&#13;
<form action="product_details.php?productId=<?php echo $row['product_id'];?    >>" method="post">
&#13;
&#13;
&#13;

应该......

&#13;
&#13;
<form action="product_details.php?productId=<?php echo $row['product_id'];?>" method="post">
&#13;
&#13;
&#13;

您发送额外的&#34;&gt;&#34;与您的产品ID