PHP cms在textarea中提交不起作用

时间:2014-04-16 09:02:17

标签: php content-management-system textarea submit

我的php中的简单cms出了问题。 我可以在textarea中获取网站内容,在我编辑之后我想将新编辑的内容发送到数据库,但那不起作用。 这是我的形式和功能

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");
}
?>

2 个答案:

答案 0 :(得分:0)

尝试更改

editContent($_GET['content']);

 editContent($_POST['contentarea']);

因为它是你要求它将内容设置为?get参数中的任何内容(我无法在其他任何地方看到引用,所以我猜测它没有填充任何内容)

:)

答案 1 :(得分:0)

当您调用函数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");
    }
    ?>