如何更新数据库中产品的价格?

时间:2012-05-30 14:17:11

标签: php mysql

我在php&中制作购物车MySQL的。我有一个问题是更新产品的价格。我的代码如下。 Plz告诉我哪里错了。我的echo语句也不起作用,只显示产品价格的方框。

<?php
include("includes/db.php");
include("includes/functions.php");

if(isset($_POST['update_price'])){
//print_r($_POST['price']);

    foreach($_POST['price'] as $priceup => $prvalue){ 

    echo $sql = "Update products SET price='$prvalue' where serial = '".     $_POST['product_data'][$priceup] ."'";
    echo $result=mysql_query($sql);}    }   



            ?>
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
         <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>Products Prices Management</title>
                  <script language="javascript">
                        function update_cart(){
             document.form1.command.value='update';
                            document.form1.submit();
              }
                 </script>

          <style type="text/css">
             <!--
            .style3 {
        font-family: Georgia, "Times New Roman", Times, serif;
font-weight: bold;
font-style: italic;
color: #FF0000;
        }
        -->
            </style>
        </head>
       <body>
        <h1 class="style3">Products Price Management</h1>
         <table border="2" cellpadding="2px" width="473">
            <?php
        $result=mysql_query("select * from products");
        while($row=mysql_fetch_array($result)){
    ?>
            <tr>
         <input type="hidden" name="product_data[]"  value="<?php echo $row['serial']; ?>" />
         <td width="205"><b><?php echo $row['name']?></b></td>

        <td width="246"><input type="text" name="price[]" value="<?php echo  $row['price']?>"maxlength="3" size="2" />
             </td>

             </tr>
             <?php
                }
               ?>
           </table>
              <div>
    <input type="submit" name="update_price" value="Update Prices" >
           </div>

             </body>
            </html>

Plz告诉我,我做错了什么?

1 个答案:

答案 0 :(得分:3)

我认为您在页面和方法POST中缺少表单标记。

<form method="POST" action="script.php">
...

</form>