繁体   English   中英

从mysql db获取值并将其发布到php页面

[英]getting a value from mysql db and post it to php page

我在从数据库中获取一个值并将其发布到另一个页面(这里是我的代码)时遇到了一个小问题。 在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>

尝试这个:

//////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函数,否则表单不会提交。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM