dousa1630 2014-03-24 14:53
浏览 12

为什么不删帖?

I wrote this code to delete per click a post out of the database table 'community_posts'. When I click on the Button, it doesn't delete it, he get the URL with do=delete&key=THEID but it doesn't work, why? Can someone help me, please!

// PHP CODE
if($do == "delete" && is_numeric($key)){
        $check = mysql_query("SELECT id FROM community_posts WHERE id = '".$key."' LIMIT 1") or die(mysql_error());

        if(mysql_num_rows($check) > 0){
                mysql_query("DELETE FROM community_posts WHERE id = '".$key."' LIMIT 1") or die(mysql_error());
                $msg = "<center>Neuigkeit wurde erfolgreich gelöscht...</center>"; } else { $msg = "<center>Neuigkeit konnte nicht entfernt werden, versuche es erneut...</center>";
        }
}

// HTML CODE UND AUSGABE DER DATENBANK
<form action='' method='post'>
<?php $getComments = mysql_query("SELECT * FROM community_posts ORDER by id DESC LIMIT 100"); ?>
<?php while($row = mysql_fetch_array($getComments)){
$getUserInfo = mysql_query("SELECT * FROM users WHERE id = '".$row['userid']."'");
$roww = mysql_fetch_array($getUserInfo); ?>

<div class="feedOne fade ptr">
        <div class="ph20">
                <div class="inner-1 lt" style=""><p style="color:#aeaeae;font-size:13px;"><a href="/community/userprofile/<?php echo $roww['username']; ?>" style="color:orange;text-decoration:none;font-weight:normal;"><?php echo $roww['vorname']; ?></a> &raquo; Open Community</p>
                <p class=lt style="color:#aeaeae;font-size:11px;"><?php echo $row['posted_on']; ?></p><br />
                </div>
                <div class="rt inner-2">
                <p style="color:#333;font-size:13px;"><?php echo $row['story']; ?></p>
                </div>
                <div class=cl></div>
        </div>

<!-- BEI KLICK SOLL HIERMIT DER ENTSPRECHENDE BEITRAG GELÖSCHT WERDEN -->
<a href='<?php echo $path_admin; ?>/openfeed?do=delete&key=<?php echo $row['id']; ?>'><img src="/assets/data/images/icons/delete_round.png" alt="delete" /></a>
<!---->

</div> 

<?php } ?>
</form>
  • 写回答

3条回答 默认 最新

  • douwen1937 2014-03-24 14:59
    关注

    Variables in the URL header are stored in the $_GET array. Instead your first line should be :

    if($_GET['do'] == "delete" && is_numeric($_GET['key'])){
    

    EDIT : You might want to check if the variable is set beforehand using the isset() method.

    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错