0

我从数据库中获取值并将其发布到另一个页面时遇到了一个小问题,这是我的代码。在 search.php 上,用户输入最低价格和最高价格,然后在页面 result.php 上,它从数据库中显示产品的名称和价格以及更多信息的链接。(info.php)这第三页将显示一些附加信息基于 result.php 上显示的产品 ID 的信息我试图从结果中隐藏 Id_product 的值并将其发布到第 3 种形式但不起作用。我收到错误通知:未定义索引:info.php 第 4 行中的 ID

//////search.php /////

<form  method="post" action="result.php" > 
<tr> <INPUT type=text size=20 name=pricemin ><BR>  </tr>  
<tr> <INPUT type=text size=20 name=pricemax ><BR>  </tr>
<tr> <input type="submit" class="Nom" id="button" value="Valider" /></tr></form>

///////result.php //////

<?php include 'includes/connection.php';
$pricemin = $_POST['pricemin'];
$pricemax = $_POST['pricemax'];
$query = "SELECT * FROM product where price between '$pricemin' and '$pricemax'";
$result = mysql_query($query);?>
<?php if(mysql_num_rows($result) > 0)
while($products = mysql_fetch_array($result)) {?>   
<?php echo $products['name_product'] ;echo $products['price_product'] ;
echo "<a href='http://localhost/mywebsite/info.php'>More infos</a>"
?>
<form method="post" action="info.php" >
<input type="hidden" name="id" value="<?php echo $products['id_product']; ?>" />
</form><?php } ?>...

///// info.php //////

<?php
include 'includes/connection.php';
$id_product = $_POST['id'];
$query = "SELECT * FROM product where id_product='$id_product'";
$result = mysql_query($query);   ?>
<html><head><title>.. </title></head><body>
<?php 
while($products = mysql_fetch_array($result)) {?>
<h1>Product ID : <?php echo  $products['id_product'] ; ?> </h1>
<h1>Product name : <?php echo  $products['name_product'] ; ?> </h1>
<h1>Product Qt : <?php echo  $products['quantity_product'] ; ?> </h1>
<h1>Product Spec : <?php echo  $products['spec_product'] ; ?> </h1>
<?php } ?></body></html>
4

1 回答 1

1

试试这个:

//////search.php /////

<form  method="post" action="result.php" > 
<tr> <INPUT type=text size=20 name=pricemin ><BR>  </tr>  
<tr> <INPUT type=text size=20 name=pricemax ><BR>  </tr>
<tr> <input type="submit" class="Nom" id="button" value="Valider" /></tr></form>

///////result.php //////

<?php include 'includes/connection.php';
$pricemin = $_POST['pricemin '];
$pricemax = $_POST['pricemax '];
$query = "SELECT * FROM product where price between '".$pricemin."' and '".$pricemax."'";
$result = mysql_query($query);

if(mysql_num_rows($result) > 0)
while($products = mysql_fetch_array($result)) {
$id = $products['id_product'];
echo $products['name_product'] ;echo $products['price_product'] ;
echo "<a href='info.php?id=";
echo $id;
echo "'>More infos</a>"
?>

<?php } ?>...

///// info.php //////

<?php
include 'includes/connection.php';
$id_product = $_GET['id'];
$query = "SELECT * FROM bien where id_product= '".$id_product."'";
$result = mysql_query($query);   ?>
<html><head><title>.. </title></head><body>
<?php 
while($products = mysql_fetch_array($result)) {?>
<h1>Product ID : <?php echo  $products['id_product'] ; ?> </h1>
<h1>Product name : <?php echo  $products['name_product'] ; ?> </h1>
<h1>Product Qt : <?php echo  $products['quantity_product'] ; ?> </h1>
<h1>Product Spec : <?php echo  $products['spec_product'] ; ?> </h1>
<?php } ?></body></html>

这应该将 ID 传递给 info.php

此外,表单仅在您提交按钮时才有效,因此如果您单击链接,除非您使用 JS onsubmit 函数,否则表单将不会提交。

于 2012-05-30T19:27:43.483 回答