HTML,PHP多种形式"结帐"

时间:2014-04-28 05:26:15

标签: php

我正在试图弄清楚如何让这段代码发挥作用。我正在试图弄清楚如何获取表单 - 由多个数据库生成的输入字段组成 - 来完成PHP我已经得到了以下内容。

    if(isset($_GET['sell']))
{
    foreach($_POST as $x=>$v)
    {
        $count = $resource->invSearch($x, $_SESSION['uid']);
        if($v != 0 || isset($v))
        {
            if($count >= $v)
            {
            $sql = "UPDATE user_inventory SET resource_count = resource_count-:ammount WHERE resource_id = :array AND uid = :uid;";
            $sql .= "INSERT INTO 
                        user_inventory(uid, resource_id, resource_count)
                    VALUES
                        (0, :array2, :ammount2) 
                    ON DUPLICATE KEY UPDATE resource_count = resource_count+1";
            $que = $db->prepare($sql);
            $que->bindParam(':uid', $_SESSION['uid']);
            $que->bindParam(':array', $x);
            $que->bindParam(':ammount', $v);
            $que->bindParam(':array2', $x);
            $que->bindParam(':ammount2', $v);
            try { $que->execute(); }catch(PDOException $e){}
            }
            else
            {
                echo $x.'|';
                echo $count.'<br />';
            }
            header('location:index.php?mode=market');
        }   
    }
}

现在是表格。

  <form action='?mode=market&sell=true' method='post'>
     <table id='leader' style='text-align: center'>
        <tr><th>Resource Name</th><th>Quantity</th><th>&nbsp;</th></tr>
         <?php $sql = "SELECT resource_id, resource_count FROM user_inventory WHERE uid = :uid";
            $que = $db->prepare($sql);
            $que->bindParam('uid', $_SESSION['uid']);
            try { 
               $que->execute();
           while($row=$que->fetch(PDO::FETCH_BOTH))
           {
            $name = $resource->get_resource_name($row[0]);
            echo "<tr><td>{$name}</td>
                              <td>{$row[1]}</td>
                              <td>
                                <input type='number' name='{$row[0]}' min='0' max='{$row[1]}'> 
                              </td>
                          </tr>";
           }
            }catch(PDOException $e){}
        ?>
       <tr>
           <td>&nbsp;</td> 
           <td>&nbsp;</td>
           <td><input type='submit' value='checkout' /></td>
       </tr>
    </table>
 </form>

0 个答案:

没有答案