0

请原谅我的标题,解释我的问题有点困难。所以就在这里。在http://appsolute.vacau.com/cms我在 textarea 中有一个变量。您可以从一开始就看到变量的输出。更新提交表单的文本就是更新变量。到目前为止一切都是正确的,对吧?提交表单时,页面会重新加载,但所有内容都来自变量的先前内容。但是在检查时,变量 WAS 更新了。即使你刷新页面。那么为什么我在提交表单后看不到变量的实际值呢?希望它是有道理的...

<html>
    <head>
        <title>Milan CMS</title><?php
$host     = "x";
$dbname   = "x";
$username = "x";
$password = "x";
$dbh      = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$sth      = $dbh->prepare("SELECT * FROM milan   ");
$sth->execute();
$result   = $sth->fetchAll();
?>
    </head>

    <body>
        <?php
        var_dump($result);
        $myFile   = "trainingen.json";
        $fh       = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, json_encode($result));
        fclose($fh);
        ?>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="trainingen">
            <h3>Trainingen:</h3><p><textarea name="nametrainingen" rows="10" cols="60"><?php echo $result[0]['value']; ?></textarea></p>
            <input name="submit" type="submit" value="Verzenden"><input type="reset" value="Veld leeg maken">
        </form>
        <?php
        $invoer   = $_POST['nametrainingen'];
        if (isset($_POST['submit'])) { //test if submit button is clicked
            $sql = "DELETE FROM milan WHERE tag = 'trainingen'";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sql = "INSERT INTO milan (tag, value) VALUES ('trainingen', '$invoer')";
            $sth = $dbh->prepare($sql);
            $sth->execute();
        }
        ?>
    </body>
</html>
4

3 回答 3

0

简单的逻辑。首先对数据库进行更改

DELETE FROM milan
INSERT INTO milan

然后从数据库加载行

SELECT * FROM milan
于 2012-08-22T21:08:52.303 回答
0

像这样重新安排逻辑:

<?php
        $invoer   = $_POST['nametrainingen'];
        if (isset($_POST['submit'])) { //test if submit button is clicked
            $sql = "DELETE FROM milan WHERE tag = 'trainingen'";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sql = "INSERT INTO milan (tag, value) VALUES ('trainingen', '$invoer')";
            $sth = $dbh->prepare($sql);
            $sth->execute();
        }

        $sth      = $dbh->prepare("SELECT * FROM milan   ");
        $sth->execute();
        $result   = $sth->fetchAll();
    ?>
       <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="trainingen">
            <h3>Trainingen:</h3><p><textarea name="nametrainingen" rows="10" cols="60"><?php echo $result[0]['value']; ?></textarea></p>
            <input name="submit" type="submit" value="Verzenden"><input type="reset" value="Veld leeg maken">
        </form>
于 2012-08-22T21:10:01.857 回答
0

您必须在输出内容之前处理您的数据。这意味着您必须遵循一定的程序:

  • 加载核心配置:数据库连接等
  • 插入/更新表和填充/预设变量
  • 从(现已更新的)数据库中选择内容
  • 输出(很可能是 html)
于 2012-08-22T21:17:13.523 回答