选中后,将数据从表中获取到另一个表

时间:2016-09-09 03:38:03

标签: php sql

这个程序正常工作我只是不知道如何使这个附加功能工作...

dbconfig.php

Setup

产品管理

在产品管理中,我将添加产品信息名称,价格,库存等。

add_form.php

Login_ValidLoginRequest_ShouldReturnValidLoginResponse()

的index.php

<?php

  $db_host = "localhost";
  $db_name = "testproduct";
  $db_user = "root";
  $db_pass = "";

  try{

      $db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
     $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   }
   catch(PDOException $e){
    echo $e->getMessage();
   }


    ?>

销售管理

这是销售中的问题我将添加一个需要产品名称的销售记录。该产品将从产品管理表中选择,包括将在指数上显示的特定产品的其他信息(实际价格,库存,销售价格)

add_form.php

<?php
  require_once 'dbconfig.php';


   if($_POST)
   {
     $fname = $_POST['name'];
     $lname = $_POST['actualprice'];
     $contactnum = $_POST['sellprice'];
     $email = $_POST['Stock'];
     try{

           $stmt = $db_con->prepare("INSERT INTO   tblproduct(name,actualprice,sellprice,Stock)  VALUES(:pname,:pactualprice,:psellprice,:pStock)");
         $stmt->bindParam(":pname", $name);
         $stmt->bindParam(":pactualprice", $actualprice);
         $stmt->bindParam(":psellprice", $sellprice);
         $stmt->bindParam(":pStock", $Stock);
         if($stmt->execute())
         {
            echo "Successfully Added";
         }
         else{
            echo "Query Problem";
         }  
         }
        catch(PDOException $e){
        echo $e->getMessage();
     }
   }


  ?>


   <style type="text/css">
    #dis{
   display:none;
  }
  </style>




    <div id="dis">

    </div>


  <form method='post' id='emp-SaveForm' action="#">

  <table class='table table-bordered'>

     <tr>
         <td>Product Name</td>
         <td><input type='text' name='name' class='form-control' placeholder='EX : john doe' required /></td>
     </tr>

     <tr>
         <td>Actual Price</td>
         <td><input type='text' name='actualprice' class='form-control' placeholder='EX : Web Design, App Design' required></td>
      </tr>

      <tr>
         <td>Sell Price</td>
         <td><input type='text' name='sellprice' class='form-control' placeholder='EX : 180000' required></td>
      </tr>

       <tr>
         <td>Stock</td>
         <td><input type='text' name='Stock' class='form-control' placeholder='EX : john doe' required /></td>
      </tr>


       <tr>
         <td colspan="2">
         <button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
         <span class="glyphicon glyphicon-plus"></span> Save this Record
         </button>  
         </td>
         </tr>

     </table>
     </form>

的index.php

<table cellspacing="0" width="100%" id="example" class="table table-striped    table-hover table-responsive">
      <thead>
      <tr>
      <th>Product Name</th>
      <th>Actual Price</th>
      <th>Sell Price</th>
      <th>Stock</th>
      <th>edit</th>
      <th>delete</th>

      </tr>
      </thead>
      <tbody>
      <?php
       require_once 'dbconfig.php';

      $stmt = $db_con->prepare("SELECT * FROM tblproduct ORDER BY id DESC");
      $stmt->execute();
      while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        ?>
        <tr>
        <td><?php echo $row['name']; ?></td>
        <td><?php echo $row['actualprice']; ?></td>
        <td><?php echo $row['sellprice']; ?></td>
        <td><?php echo $row['Stock']; ?></td>
        <td align="center">
        <a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
        <img src="edit.png" width="20px" />
        </a></td>
        <td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
        <img src="delete.png" width="20px" />
        </a></td>
        </tr>
        <?php
     }
     ?>
    </tbody>
    </table>

1 个答案:

答案 0 :(得分:0)

在这种情况下使用ajax更好的方法。

$.ajax({
            url: "data.php",//file wich has query select to db table
            data: {id:theid},//describe your data here
            dataType: 'json',// type of data that will you get (JSON/HTML).
            type: 'POST',//sending type (POST/GET)
            success: function(data) {
               showTable();
            }
        });