Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 删除查询无法删除库存_Php_Html - Fatal编程技术网

Php 删除查询无法删除库存

Php 删除查询无法删除库存,php,html,Php,Html,我正在实施服装购物网站,其中管理员管理库存,例如添加,更新,删除库存。我的删除查询有问题。库存显示在表中,每行都有自己的删除按钮。当我点击delete按钮时,它总是使用最后一行id并删除该行,而不是我想要的那一行。查询始终采用最后一行id。 代码: 产品代码 烙印 价格 性别 类别 材料 大小 描述 量 删除股票 您的脚本始终使用post中的最后一行,因为您的所有数据都只有一个表单,并且您的最后一个值将覆盖所有以前的数据。Intead of it从表的外侧删除表单将其添加到td,在td中指定隐

我正在实施服装购物网站,其中管理员管理库存,例如添加,更新,删除库存。我的删除查询有问题。库存显示在表中,每行都有自己的删除按钮。当我点击delete按钮时,它总是使用最后一行id并删除该行,而不是我想要的那一行。查询始终采用最后一行id。 代码:


产品代码
烙印
价格
性别
类别
材料
大小
描述
量
删除股票

您的脚本始终使用post中的最后一行,因为您的所有数据都只有一个表单,并且您的最后一个值将覆盖所有以前的数据。Intead of it从表的外侧删除表单将其添加到td,在td中指定隐藏字段并单击“删除”按钮。如下图所示:

<table align="center" border="0" id="myTable" class="table table-striped table-bordered table-list">
    <tr>
      <th>Product Code</th>
      <th>Brand</th>
      <th>Price</th>
      <th>Gender</th>
      <th>Category</th>
      <th>Material</th>
      <th>Size</th>
      <th>Description</th>
      <th>Quantity</th>
      <th>Delete Stock</th>
      </tr> 

<?php
$sql = "SELECT * FROM add_stock  ORDER BY id DESC"; 
                $rs_result = mysqli_query ($sql);
                   while ($result=mysqli_fetch_array($rs_result) )
            {
              ?>
              <tr>

                <td><?php echo $result['id'];?></td>
                <td><?php echo $result['brand_name'];?></td>
                <td><?php echo $result['price'];?></td>
                <td><?php echo $result['gender_name'];?></td>
                <td><?php echo $result['category_name'];?></td>
                <td><?php echo $result['material_name'];?></td>
                <td><?php echo $result['size_name']; ?></td>
                <td><?php echo $result['dress_description'];?></td>
                <td><?php echo $result['dress_quantity'];?></td>
               <td><form action="" method="post" name="deleting" ><input type="hidden" name="ID" value="<?php echo $result['id']; ?>"><input type="submit" name="delete" value="Delete" ></form></td>

              </tr>
              <?php
            }      
            ?>
</table>

产品代码
烙印
价格
性别
类别
材料
大小
描述
量
删除股票

我建议不要仅仅为了删除而使用
。您可以使用


您已经采取了“仅删除”的形式,或者您还必须执行其他操作?我只是使用“删除查询”的形式@B.Desahi@ShoaibSharoon:希望您还记得我。到目前为止,你已经问了11个问题,没有一个问题有明确的答案。我在一周前提醒过你同样的事情。但是,你仍然没有标记任何人。看见人们努力让你摆脱这个问题。所以,通过将他们的答案标记为正确答案来奖励他们。是的,你已经问了4次这个问题了。。。如果你没有得到答案,大多数时候问题是问题本身;要么不够清楚,要么你表现得太不努力了。我知道你是新来的,但是请试着问一下,不要把我们当作你的私人雇员。没有人会为你写完整的代码。还有一件事,我写答案不仅仅是为了名誉。我不管你是否做标记。但是,要努力找出错误在哪里。我已经回答了,你也回答说谢谢。而且,如果4-5天后它不起作用,那么,这不是我的问题。我不会坐着检查你的密码。你没有在ShoaibSharoon努力寻找问题
<table align="center" border="0" id="myTable" class="table table-striped table-bordered table-list">
    <tr>
      <th>Product Code</th>
      <th>Brand</th>
      <th>Price</th>
      <th>Gender</th>
      <th>Category</th>
      <th>Material</th>
      <th>Size</th>
      <th>Description</th>
      <th>Quantity</th>
      <th>Delete Stock</th>
      </tr> 

<?php
$sql = "SELECT * FROM add_stock  ORDER BY id DESC"; 
                $rs_result = mysqli_query ($sql);
                   while ($result=mysqli_fetch_array($rs_result) )
            {
              ?>
              <tr>

                <td><?php echo $result['id'];?></td>
                <td><?php echo $result['brand_name'];?></td>
                <td><?php echo $result['price'];?></td>
                <td><?php echo $result['gender_name'];?></td>
                <td><?php echo $result['category_name'];?></td>
                <td><?php echo $result['material_name'];?></td>
                <td><?php echo $result['size_name']; ?></td>
                <td><?php echo $result['dress_description'];?></td>
                <td><?php echo $result['dress_quantity'];?></td>
               <td><form action="" method="post" name="deleting" ><input type="hidden" name="ID" value="<?php echo $result['id']; ?>"><input type="submit" name="delete" value="Delete" ></form></td>

              </tr>
              <?php
            }      
            ?>
</table>
<table align="center" border="0" id="myTable" class="table table-striped table-bordered table-list">
  <tr>
    <th>Product Code</th>
    <th>Brand</th>
    <th>Price</th>
    <th>Gender</th>
    <th>Category</th>
    <th>Material</th>
    <th>Size</th>
    <th>Description</th>
    <th>Quantity</th>
    <th>Delete Stock</th>
  </tr> 
  <?php
  $sql = "SELECT * FROM add_stock  ORDER BY id DESC";
  $rs_result = mysqli_query($sql);
  while ($result = mysqli_fetch_array($rs_result)) {?>
    <tr>
      <td><?php echo $result['id']; ?></td>
      <td><?php echo $result['brand_name']; ?></td>
      <td><?php echo $result['price']; ?></td>
      <td><?php echo $result['gender_name']; ?></td>
      <td><?php echo $result['category_name']; ?></td>
      <td><?php echo $result['material_name']; ?></td>
      <td><?php echo $result['size_name']; ?></td>
      <td><?php echo $result['dress_description']; ?></td>
      <td><?php echo $result['dress_quantity']; ?></td>
      <td>
        <a href="deleteStock.php?id=<?php echo $result['id'];?>">
          <input type="button" value="Delete" >
        </a>
      </td>
    </tr>
    <?php }?>
</table>

<?php
if(isset($_GET['delete'])){
  if($_GET['delete'] == "success"){
    echo '<script>alert("Record removed successfully!")</script>';
  }

  if($_GET['delete'] == "fail"){
    echo '<script>alert("An unexpected error occured while <b>deleting</b> the record, Please try again!")</script>';
  }
}

?>
<script>
$(document).on('click', "#myTable a", function(e) {
  if(confirm("Are you sure want to delete this record?")) {
    return true;
  } else {
    return false;
  }
});
</script>
<?php
if (isset($_GET['id'])) {
  $id = $_GET['id'];  
  $link = mysqli_connect("localhost", "root", "") or die("Cannot Connect to the database!");
  mysqli_select_db("login", $link) or die("Cannot select the database!");
  $query = "DELETE FROM add_stock WHERE id = $id";

  $result = mysqli_query($query, $link) or die(mysqli_error($link));

  if($result){
    header("location:index.php?delete=success");
  } else {
    header("location:index.php?delete=fail");
  }
}?>