douxian4376 2015-08-07 17:33
浏览 46

从MySql中删除一行

I am attempting to add a button to my html table that will allow a user to delete a specific row when clicked.

I have the following so far but do not understand why the corresponding database table row is not being deleted when I click the borrar (delete) button.

What part am I missing?

<?php do { ?>
  <table width="263" border="1">
    <tr>
      <td><?php echo $row_Recordset1['name']; ?></td>
      <td><form id="form1" name="form1" method="post" action="">
        <input type="submit" name="borrar" id="borrar" value="Borrar" />
      </form></td>
    </tr>
  </table>
  <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

<?php

if(isset($_POST['borrar'])){

  if ((isset($_POST['id'])) && ($_POST['id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM carrito WHERE id=%s",
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_PY, $PY);
  $Result1 = mysql_query($deleteSQL, $PY) or die(mysql_error());

  $deleteGoTo = "http://fb.com";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}
}
?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
  • 写回答

1条回答 默认 最新

  • du512926 2015-08-07 18:30
    关注

    You're not passing a row 'id' from you form.

    <table width="263" border="1">
        <tr>
          <td><?php echo $row_Recordset1['name']; ?></td>
          <td><form id="form1" name="form1" method="post" action="">
    
            <!-- NEW LINE BELOW  -->
            <input type="hidden" name="id" value="<?php echo $row_Recordset1['id']; ?>" />
    
            <input type="submit" name="borrar" id="borrar" value="Borrar" />
          </form></td>
        </tr>
      </table>
    

    Your form should look like the example above.

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答