简体   繁体   English

分别从两个单独的MySQL表中删除信息?

[英]Delete Info From Two Separate MySQL Tables Individually?

I'm making this podcast-sharing like site where users can upload audio pod-casts and if they log into the admin page can edit each title and each URL, and delete any podcast. 我正在制作一个类似于播客共享的网站,用户可以在其中上传音频播客,如果他们登录到管理页面,则可以编辑每个标题和每个URL,以及删除任何播客。 Here's my code, I will explain my error afterwards: 这是我的代码,之后我将解释我的错误:

    <li><form action="admin.php" method="POST"><input type="submit" name="1" value = "Insects and Plants" /><input type="submit" name="2" value = "Dr. Seuss" /></forM>
    <li><p><?php
    function disp($titid,$titol,$aid){

            if($_GET['del']){
            $delete_id=$_GET['del'];
            mysql_query("DELETE FROM `$titid` WHERE `$titid`.`inid` = $delete_id");
            header("location: admin.php");

            }
    echo "<a name='$aid'><h3>" . $titol . "</h3></a>";
    $result=mysql_query('SELECT * FROM `'.$titid.'` ORDER BY inid ASC');
            while($row=mysql_fetch_array($result))
            {
            $title = $row['title'];

            $url=$row['url'];
            $id = $row['inid'];
            echo '<div class="inneredit">';
            echo $title . '</br>';
            echo $url . '</br>'.$id.'</br>';

                    echo "<form action='admin.php' method='POST'><input type='text' name='nameedit".$id."' /><input type='submit' name='nameit$id' value='Edit Name' /></form>";
            echo "<form action='admin.php' method='POST'><input type='text' name='urledit".$id."' /><input type='submit' name='redit$id' value='Edit URL' /></form>";
            echo "<input type='button' id='delete' value='Delete Podcast' onclick='return Deleteqry($id)' />";
            echo "</div>";
            if(isset($_POST['urledit'.$id]));
                    if(isset($_POST['redit'.$id]))
                    {
                        $newd = $_POST['urledit'.$id];

                        mysql_query("UPDATE `$titid` SET url = '$newd' WHERE $titid.inid = $id ");
                        header("location: admin.php");
                    }
                                    if(isset($_POST['nameit'.$id]))
                    {
                        $newd = $_POST['nameedit'.$id];

                        mysql_query("UPDATE `$titid` SET title = '$newd' WHERE $titid.inid = $id ");
                        header("location: admin.php");
                    }
            }

            }
            if(isset($_POST['2'])){
            disp("DrSeuss","Dr. Seuss","Seussa");

            } else {
            disp("insects","Insects and Plants","Insectsa");
    }
            ?>
    <script>
            function Deleteqry(id)
            { 
              if(confirm("Are you sure you want to delete this audio file?")==true)
                       window.location="admin.php?del="+id;
                return false;
            }

    </script>



            ?>

So now when I click delete after selecting 'Dr. 所以现在当我选择“博士”后单击“删除”时 Seuss' it deletes the podcast (with that same id) but in the Insects table, and not the Dr. Seuss table. 苏斯(Seuss)会删除播客(具有相同的ID),但会删除“昆虫”表中的播客,而不是苏斯博士表中的。 Can anyone help with how to help PHP differentiate between the two tables? 任何人都可以帮助如何帮助PHP区分两个表吗?

看一下您的js函数,便会发现您没有设置$ _POST ['2'],因此不会执行DrSeuss上的if条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM