PHP Mysql - 删除按钮继续删除最新行 [英] PHP Mysql - Delete button keeps on deleting latest row

查看:151
本文介绍了PHP Mysql - 删除按钮继续删除最新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我遇到一个毛刺,我总是找到找到答案StackOverflow,但这一次,虽然我确定修复很容易,我只是不能似乎得到它的权利!

When i run into a glitch, I always find find the answer on StackOverflow, but this time, although I'm sure the fix is easy, I just can't seem to get it right !

基本上,我试图在从我的mysql数据库获取的每一行旁边添加一个删除按钮。如果需要,用户应该能够删除特定的帖子。

Basically, i'm trying to add a "delete" button next to each row fetched from my mysql database. The users should be able to delete a specific post, if needed.

当我点击删除按钮,它总是被删除的最新行。所以我想在每一行传递的值有错误:看起来他们被最新的一个覆盖。

When i hit the delete button, it's always the latest row that gets deleted. So i guess there's something wrong with the value passed in each row : seems like they're overridden by the latest one.

下面是我的代码:

<?php  
$table = query("SELECT post, postid FROM post_list WHERE id = ? ORDER BY 
time DESC LIMIT 15", $_SESSION["id"]);
foreach ($table as $row) 
{ 
      $post = $row["post"];
      $postid = $row["postid"];  
      echo ("<table>");
      echo ("<tr>");
      echo("<td>" . $post . "</td>");
      echo("</td>")?>            
      <div id="posteraser">
       <form action='' method='post'>
          <input type='hidden' name='postid' value='<?php echo $postid?>'>
          <input type='submit' name='posteraser'>Delete</input>
       </form>
      </div>       
     <?php 
     echo ("</td>");
     echo ("</tr>");
     echo ("</table>");
     echo '<hr>';
}  
?>

在同一页面上有删除按钮代码:

And below on the same page, there's the delete button code:

<?php
if(isset($_POST['posteraser']))
{
    $sql = query("DELETE FROM post_list WHERE postid = '$postid' ");       
    redirect ('home.php');
}
?>

任何帮助/提示将非常感谢!
非常感谢!

Any help/tips will be much appreciated ! Thanks a lot !

推荐答案

您必须在这里传递 $ _ POST ['postid ']

if(isset($_POST['posteraser'])){
   $postid = $_POST['postid'];
   $sql = query("DELETE FROM post_list WHERE postid = '$postid' ");       
   redirect ('home.php');
}

b
$ b

OR as procedure way

$sql = query("DELETE FROM post_list WHERE postid = ? ",$postid);  

这篇关于PHP Mysql - 删除按钮继续删除最新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆