内容管理系统-PHP cms在文本区域提交不工作


content management system - PHP cms submit in textarea not working

我在php中的简单cms遇到了一个问题。我可以在文本区获取网站内容,编辑后我想将新编辑的内容发送到数据库,但这不起作用。这是我的表格和功能

editContent.php

    <html>
    <head>
    <title> Basic CMS - Admin Area</title>
    <h1>Admin Area Edit Content</h1>
    </head>
    <body>
    <?php
    include ('includes/functions.php');
    $cont = getContent();
    session_start();
    if(isset($_SESSION['user'])) {
    ?>
    <span>Logged In! Welcome <?php echo $_SESSION['user']; ?></span>
    <a href="logout.php">Logout</a>
    <a href="editContent.php">Wijzig content</a>
    <a href="index.php">Admin Home</a>
    <form action="doEditcontent.php" method="post">
    <textarea name="contentarea"><?php echo $cont['content'];?></textarea><br>
    Submit : <input type="submit" value="submit" />
    </form>
<?php
} else {
    header("Location: login.php");
}
?>
</body>
</html> 

functions.php

<?php
include('includes/connect.php');
function getContent(){
    $query = mysql_query("SELECT content FROM taalcontent WHERE taalid = 1 AND contentid = 1") or die (mysql_error());
    return mysql_fetch_assoc($query);
    echo $query;
}
function editContent($pContent) {
    if(isset($pContent)){
        $query = "UPDATE taalcontent SET content content = '$pContent'  WHERE contendid = 1 AND taalid = 1";
    } else {
        echo "fout";
    }
    mysql_query($query);
}

doEditcontent.php

<?php
include('includes/functions.php');
if(isset($_POST['submit'])) {
    if(isset($_POST['contentarea'])){       
        editContent($_POST['contentarea']);
        header("Location: ../index.php?page=2");   
    } else 
        echo "Please enter some content!";
} else {
    header("Location: ../index.php?page=1");
}
?>

尝试更改

editContent($_GET['content']);

 editContent($_POST['contentarea']);

事实上,你要求它将内容设置为?get参数中的任何内容(我看不到它在其他任何地方被引用,所以我猜它没有填充任何内容)。

:)

调用函数editContent($pContent)时传递了错误的参数。此外,您应该在引用函数之前对其进行定义。试试这个方法:

    <form action="doEditcontent.php" method="post">
    <textarea name="contentarea"><?php echo $cont['content'];?></textarea><br>
    Submit : <input type="submit" value="submit" />
    </form>
    <?php
    include('includes/functions.php');

    function editContent($pContent) {
if(isset($pContent)){
    $query = "UPDATE taalcontent SET content content = '$pContent'  WHERE contendid = 1 AND taalid = 1";
} else {
    echo "fout";
}
mysql_query($query);
    }

    if(isset($_POST['submit'])) {
if(isset($_POST['contentarea'])){       
    editContent($_POST['contentarea']);
    header("Location: ../index.php?page=2");   
} else 
    echo "Please enter some content!";
    } else {
header("Location: ../index.php?page=1");
    }
    ?>