简体   繁体   English

根据表单字段显示相关信息

[英]Displayin relative information depending upon form field

OK, Im working on an ordering system. 好的,我正在订购系统上。 When the user logs in they are presented with a list of vendors along with that vendors address and so on. 当用户登录时,将向他们显示供应商列表以及该供应商地址等。 Then under each vendor is a list of their product and box where they can input the quanity of each product they want. 然后,在每个供应商下面是他们的产品和框的列表,他们可以在其中输入所需每种产品的数量。

I know how i can pass the quanity to the next page but im having trouble figuring out how im going to pass the vendor information for where the order is associated for instance if they placed an order for 25 of something for one vendor then on the confirm page it would put the quanity and diplay the vendor for which the order is associated. 我知道如何将数量传递给下一页,但是我无法弄清楚如何将供应商信息传递给与订单相关的位置,例如,如果他们为一个供应商下了25件东西的订单,然后在确认时页面,它将放置数量,并且与与订单关联的供应商不匹配。

My code is below. 我的代码如下。 Any help will obviously be greatly appreciated and there's a chance i'll let you name my first born. 很显然,任何帮助将不胜感激,并且有机会我会让您命名我的第一胎。 Assuming i ever have kids and that's a big assumption. 假设我曾经有孩子,那是一个很大的假设。

<form name="OrderForm" action="/confirm" method="POST">
    <?php $query = 'SELECT * FROM Vendors WHERE VendorID = 1';
        $productquery = 'SELECT * FROM Products WHERE VendorID =  1';
$results = $db->getAll($query);
$productresults = $db->getAll($productquery);?>
 <table class="table">
              <thead>
                <tr>
                  <th>Quantity/Product</th>
                  <th>Category</th>
                  <th>Vendor</th>
                  <th>Address</th>
                </tr>
<?php

foreach ($results as $vendor) {
?>
<tr class="category">
    <td></td>
    <td><?php echo $vendor['Category'];?></td>
    <td><?php echo $vendor['Vendor'];?></td>
    <td><?php echo $vendor['Address'];?></td>

    </tr> 
    <?php

 foreach ($productresults as $product){
    ?>

     <tr class="product">
    <td colspan="4"><span class="name"><input type="text" name="quantities[]" size="1" /><?php echo $product['Product'];?></span></td>

    </tr>
    </table>
<input type="submit" value="Checkout"<button style="float:right;" type="button" class="btn btn-primary"></button>
</form>

When you link them to the next page, use something like orderpage.php?vendor=$vendor[vendor] or the vendor ID, so you can grab the vendor info from the next page. 当您将它们链接到下一页时,请使用诸如orderpage.php?vendor=$vendor[vendor]或供应商ID之类的名称,以便从下一页获取供应商信息。 You can do it like this: 您可以这样做:

<td><a href="orderpage.php?vendor=<?php echo $vendor['Vendor'];"?>> <?php echo $vendor['Vendor'];?> </td></a>

In order to get the vendor value from the url, you do the following: 为了从URL获取供应商值,请执行以下操作:

$vendor = $_GET['vendor'];

And you will have the necessary information to run a query and grab all the vendor info. 然后,您将具有运行查询并获取所有供应商信息的必要信息。 That's the easiest way. 那是最简单的方法。

IMPORTANT: Make sure to filter $vendor variable appropriately, as users can and will try to mess with it by adding code after ?vendor= , so depending on what value you want to pass (id number, special character, vendor name etc) filter the $_GET['vendor'] so only your information can be passed to the query. 重要说明:确保适当地过滤$vendor变量,因为用户可以并且会尝试通过在?vendor=之后添加代码来弄乱$vendor变量,因此取决于要传递的值(id号,特殊字符,供应商名称等)过滤器$_GET['vendor']因此只有您的信息可以传递给查询。

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

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