php - 为什么我的 'if (isset) does not interact with mysql'

标签 php mysql json isset

为什么我的'if if (isset($_POST['submit'])) 不与 mysql 交互' 请告诉我,我哪里出错了,我已经检查过这个一千次并检查了互联网......这是很多代码,但我想我已经监督了一些东西。我为自己做了评论,所以我不会忘记像“;”这样愚蠢的东西。
提前致谢

http://appsolute.vacau.com/cms

<html>
    <head>
    <title>Milan CMS</title>
    </head>

    <body>
    <?php
    mysql_connect("mysql15.000webhost.com", "a96443****tjiran", "ev****89") or die(mysql_error()); //opening database
    mysql_select_db("a9644326_app") or die(mysql_error());
    $result = mysql_query("select * from milan") or die(mysql_error()); //get msql database into $result
    $content = mysql_fetch_array ($result); // make $content represent current entry
    ?>

    <form action="<?php echo $PHP_SELF;?>" method="post" name="trainingen">
    <h3>Trainingen:</h3><p><textarea name="nametrainingen" rows="10" cols="60"><?php echo $content['value']; ?></textarea></p>
    <input type="submit" value="Verzenden"><input type="reset" value="Veld leeg maken">
    </form>

    <?php
    if (isset($_POST['submit'])) 
    { //test if submit button is clicked
        mysql_query("DELETE FROM milan WHERE tag='trainingen'") or die(mysql_error()); //delete old entry
        $input = $_POST['nametrainingen']; //set $input as current entry
        mysql_query("INSERT INTO milan (tag, value) VALUES ('trainingen', '$input')") or die(mysql_error()); //set tag, value as trainingen and $input(current entry)
        $result = mysql_query("select * from milan") or die(mysql_error()); //reset $result to new database
        $content = mysql_fetch_array ($result); //make $content represent new entry
        $myFile = "trainingen.json"; 
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, json_encode($content));
        fclose($fh);
    }
    ?>
    <p>
    </body>
</html>

最佳答案

$_POST 是一个 super 全局数组,它包含与表单一起提交的所有表单元素的关联数组。您没有使用 name="submit" 的输入,因此您的 isset() 失败。

关于php - 为什么我的 'if (isset) does not interact with mysql',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12035487/

相关文章:

php - 反序列化时 Laravel 通知失败

php - 每次我点击商店名称时都会抛出错误而不是打印位置

javascript - 如何获取对象内的数组,删除双引号并将其作为对象放入 json 语法中

php - laravel Eloquent 一对多关系返回null

javascript - 如何下载我从 Google Picker API 选择的文件?

php - 如何通过 Codeception 在命令行中使用动态 url 进行验收测试

mysql - 2 个数据库,还是 1 个?

mysql - 如何在mysql中显示分组依据?

python - JSON 编码的超长迭代器

javascript - 以 Angular 获取 json 数组中的第一项?