douyuan4357 2015-05-16 07:30
浏览 11

显示来自不同页面上的while循环的特定id的信息

I created an admin function to be able to display/add/edit products that are on my site. I am having no issues with adding and fetching/displaying what products are on my site.

Being able to see the current product I am trying to edit is where I am having difficulties. I am displaying the products that are in my database by fetching all of them through a while loop. I added an edit link that goes to editproducts.php.

The problem I am having is I am not sure how to get the product's data that I clicked on to display and fetch just that product_id's data.

The way I display all of the products

<table class="tableproduct">
                        <tr>
                            <th class="thproduct">Product ID</th>
                            <th class="thproduct">Product Name</th>
                            <th class="thproduct">Price</th>
                            <th class="thproduct">Category</th>
                            <th class="thproduct">Description</th>
                            <th class="thproduct"></th>
                            <th class="thproduct"></th>
                        </tr>   
<?php
 if(isset($_POST['product_id']) && is_numeric($_POST['product_id'])) {
       mysqli_query($con, "DELETE FROM products WHERE product_id = ". $_POST['product_id'] ."")
       or die("Could not DELETE: " . mysqli_error($con)); 
       "Your product was successfully deleted."; 
}   else {Session::flash('addproduct', 'Your product was successfully deleted.');
}


if( $result ){  
        while($row = mysqli_fetch_assoc($result)) :
?>
                         <form method="POST" action="adminproducts.php">
                            <tr>
                                <td class="tdproduct"><?php echo $row['product_id']; ?> </td>
                                <td class="tdproduct"><?php echo $row['name']; ?> </td> 
                                <td class="tdproduct"><?php echo $row['price']; ?> </td>
                                <td class="tdproduct"><?php echo $row['category']; ?> </td>
                                <td class="tdproduct"><?php echo $row['description']; ?> </td>
                                <td class="tdproduct"><a href='editproducts.php?product_id=<?php echo $row['product_id']; ?>'>EDIT</a></td>
                                <input type="hidden" name="product_id" value="<? echo $row['product_id']; ?>"/>
                                <td class="tdproduct"><input name="delete" type="submit" value="DELETE "/></td>
                            </tr>
                        </form>
<?php   
        endwhile; 
        }
?>
                        </table>

The page where I want to edit the product.

I tried the GET function and pulling the product_id. This does nothing. The name and price that I am trying to echo at the bottom of the code does not display anything other than the echoed string '$'.

<?php
$_GET['product_id'];
?>
                <form action="" method="post">
                        <div class="field">
                            <label for="product_id">Product ID</label>
                            <input type="text" name="product_id" class="inputbar">
                        </div>
                        <div class="field">
                            <label for="name">Product Name</label>
                            <input type="text" class="inputbar" name="name">
                        </div>
                        <div class="field">
                            <label for="price">Price</label>
                            <input type="text" class="inputbar" name="price">
                        </div>
                        <div class="field">
                            <label for="category">Category</label>
                            <input type="text" class="inputbar" name="category">
                        </div>
                        <div class="field">
                            <label for="description">Description</label>
                            <input type="text" class="inputbar" name="description">
                        </div>  

                            <input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
                            <label for="signinButton">
                                <input type="submit" id="signinButton" value="Update">
                            </label>
                </form>

                            <p><?php echo "<a href='./viewProduct.php?view_product=$id'>" . $product['name'] . "</a>"; ?></p>
                            <p> <?php echo "$" . $product['price']; ?> </p> 

Is there something I'm not doing correctly or over-looking?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据