php - 在同一页面添加mysql和删除

标签 php mysql forms post

这是我的脚本

require('dbcon2.php');


  if(isset($_GET['submit1'])) { 
        if(isset($_POST['post_autor']) && isset($_POST['post_tresc'])) {

            mysqli_query($connect,"INSERT INTO news (tresc, autor) VALUES ('$_POST[post_tresc]', '$_POST[post_autor]')");

        }

  } elseif(isset($_GET['submit2'])) {

        if(isset($_POST['post_id_news2'])) {
            $usun = $_POST['post_id_news2'];

            mysqli_query($connect,"DELETE FROM news WHERE id_news = ".$usun."");
        }   else {
            echo 'Proba usunieca postu o pustym id.';
        }

    }

我想在一页上执行此操作,在添加删除之前(呵呵)没关系,但我想做删除选项,但没有任何作用,零错误,我只是按输入,什么也没有发生。

HTML:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
    <head>
        <meta charset="utf-8">

        <style type="text/css">
            .cztery {
                    background: pink;
                    height:705px; 
                    width:40%;
                    float:right;
                }
            .czteryipol {
                    background: red;
                    height:705px; 
                    width:40%;
                    float:right;
                }
            </style>
    </head>
    <body> 
        <div class="cztery">
            <h1 align="center">
                <a href="html/news_podg.php" target="_blink">
                    PODGLĄD
                </a>
            </h1>
            <table border="5"  bordercolor="#a64dff" align="center" style="max-width:20px;">
                <?php
                    $result = mysqli_query($connect,"SELECT autor,id_news FROM news GROUP BY id_news");
                    while($row = mysqli_fetch_array($result)) 
                    { 
                    echo '<tr><td>'.$row['id_news'].'</td><td>'.$row['autor'].'</td></tr>';
                    }
                ?>
            </table>
        </div>
        <div class="czteryipol">
            <h1 align="center">
                EDYCJA
            </h1>
             <form action="kwadrat.php?go=czesc" method="post" id="usrform" align="center">

                <h2>
                    Autor<br> <input type="text" size="20" name="post_autor"/>
                </h2>


                <h2>
                    Dodaj artykuł: 
                </h2>
                <textarea name="post_tresc" align="center" form="usrform"></textarea><br>

            <input name="submit1" type="submit" value="OK"/><br>
        </form>

         <form action="kwadrat.php?go=czesc" method="post" id="usrform" align="center">
            <h1 align="center">
                Usuń artykuł
            </h1>   
            <h2>
                    Numer artykułu<br> <input type="text" size="5" name="post_id_news2"/>
            </h2>   
            <input name="submit2" value="OK" type="submit"/><br>  
        </form>
        </div>
    </body>
</html>

如果有人能告诉我我的错误在哪里,我将非常感激

最终编辑:

感谢您的帮助,我解决了这个问题:

而不是这个

($_GET['submit1']) 

($_POST['submit1'])

最佳答案

大概...... 而不是if(isset($_GET['submit1'])) 使用if(isset($_POST['submit1']))

关于php - 在同一页面添加mysql和删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42590326/

相关文章:

Mysql联合查询记录结果清空列

database - 英语、葡萄牙语和西类牙语的国家和国籍列表?

php - 以下mysql查询有什么问题

php - command exec 和 php shell_exec 有不同的结果

MySQL:找到搜索字符串的字段列表?

ruby-on-rails - 防止修改 ("hacking") 隐藏字段在 rails3 中的形式?

带有混合输入标签的 html 表单(类型=文件和其他)

php - 使用表达式或 jQuery 更改 Laravel Blade 中的 div 宽度

php - 在文本字符串中识别人的名字和姓氏的最佳方法

Mysql请求。从两个表中选择