PHP 表单发送变量问题

发布于 2024-12-01 05:03:08 字数 2700 浏览 2 评论 0原文

我正在与 PHP AJAX CKEDITOR 和 MySQL 作斗争,因为我想通过按底部的按钮将屏幕上的所有内容(包括输入文本框)和 CKeditor 文本保存到 mysql 中。

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<?php include("db_connect.php"); ?>
<?php include("menu.php"); ?>
<h1>New Project</h1>

<form method="post" action="">
    New project name:<input type="text" name="pr-name" placeholder="new project name..."><br/>
    New project end date:<input type="text" name="pr-end" placeholder="date..."><br/>
    New project type:
    <select name="pr-menu">
        <?php 
        $listdata = mysql_query("SELECT * FROM lists WHERE tag='prtype' ORDER BY listing ASC");
        while($listresult = mysql_fetch_array($listdata))
    {
        $link = '';
        if($listresult['listing'] != '...') {
            $link = $listresult['value'] . ".php";
            echo "<option value='$link'>${listresult['listing']}</option>";
        }

    }
    ?>
</select>

<div id="page">
    <!-- container for loaded page -->
</div>

<script type="text/javascript">
    $("select[name=pr-menu]").change(function() {
        var url = $("option:selected", this).val();
        // Load a page to the container
        $("#page").load(url);
    });
</script>

</form>

<?php
if($_REQUEST["submit"] == "continue ->")
{
$prname = mysql_real_escape_string ($_REQUEST["pr-name"]);
$prend = mysql_real_escape_string ($_REQUEST["pr-end"]);
$prmenu = mysql_real_escape_string ($_REQUEST["pr-menu"]);
$prcontent = mysql_real_escape_string ($_REQUEST["pagecontent"]);

$sql = "INSERT INTO projects (name,enddate, sel, content) VALUES('$prname','$prend', '$prmenu', '$prcontent')";
mysql_query($sql);
}
?>

</body>
</html>

其中代码选择不同的php文件来扩展表单。其中一种形式也有 CKEDITOR。

<textarea class="ckeditor" name="pagecontent"  id="pagecontent"></textarea>

<?php
include_once "ckeditor/ckeditor.php";
$CKEditor = new CKEditor();
$CKEditor->basePath = 'ckeditor/';

// Set global configuration (will be used by all instances of CKEditor).
   $CKEditor->config['width'] = 600;   
// Change default textarea attributes
   $CKEditor->textareaAttributes = array(“cols” => 80, “rows” => 10);

   $CKEditor->replace("pagecontent");

?>
<input id="submitButton" type="submit" value="continue ->"/>

我想将两个输入和编辑后的 ​​CKEDITOR 内容放在 SQL 中...

我只是找不到如何将它们链接在一起的解决方案...作为初学者,我花了几个小时... :( 希望有人可以提供帮助。

提前非常感谢

Andras

I am struggling with PHP AJAX CKEDITOR and MySQL as I would like to save everything from the screen (includes input text boxes) and CKeditor text to an mysql by pressing a button at the bottom.

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<?php include("db_connect.php"); ?>
<?php include("menu.php"); ?>
<h1>New Project</h1>

<form method="post" action="">
    New project name:<input type="text" name="pr-name" placeholder="new project name..."><br/>
    New project end date:<input type="text" name="pr-end" placeholder="date..."><br/>
    New project type:
    <select name="pr-menu">
        <?php 
        $listdata = mysql_query("SELECT * FROM lists WHERE tag='prtype' ORDER BY listing ASC");
        while($listresult = mysql_fetch_array($listdata))
    {
        $link = '';
        if($listresult['listing'] != '...') {
            $link = $listresult['value'] . ".php";
            echo "<option value='$link'>${listresult['listing']}</option>";
        }

    }
    ?>
</select>

<div id="page">
    <!-- container for loaded page -->
</div>

<script type="text/javascript">
    $("select[name=pr-menu]").change(function() {
        var url = $("option:selected", this).val();
        // Load a page to the container
        $("#page").load(url);
    });
</script>

</form>

<?php
if($_REQUEST["submit"] == "continue ->")
{
$prname = mysql_real_escape_string ($_REQUEST["pr-name"]);
$prend = mysql_real_escape_string ($_REQUEST["pr-end"]);
$prmenu = mysql_real_escape_string ($_REQUEST["pr-menu"]);
$prcontent = mysql_real_escape_string ($_REQUEST["pagecontent"]);

$sql = "INSERT INTO projects (name,enddate, sel, content) VALUES('$prname','$prend', '$prmenu', '$prcontent')";
mysql_query($sql);
}
?>

</body>
</html>

Which code select different php files to extend the form. One of the form has CKEDITOR as well.

<textarea class="ckeditor" name="pagecontent"  id="pagecontent"></textarea>

<?php
include_once "ckeditor/ckeditor.php";
$CKEditor = new CKEditor();
$CKEditor->basePath = 'ckeditor/';

// Set global configuration (will be used by all instances of CKEditor).
   $CKEditor->config['width'] = 600;   
// Change default textarea attributes
   $CKEditor->textareaAttributes = array(“cols” => 80, “rows” => 10);

   $CKEditor->replace("pagecontent");

?>
<input id="submitButton" type="submit" value="continue ->"/>

And I would like to put the up two input AND the edited CKEDITOR content in a SQL...

I just can't find the solution how to link these together... and I have spent a few hours as a beginner... :( hope someone can help.

Thank you very much in advance

Andras

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢望 2024-12-08 05:03:08

从我在代码中看到的来看,编辑器应该正确加载。

首先 - 您缺少 标签。没有它它应该几乎一直可以工作,但以防万一。
其次 - 您缺少输入名称。
第三 - 您缺少提交按钮。
第四 - 您缺少一些处理提交的代码

这段代码应该看起来像

if($_REQUEST["sumbit"] == "somevalue")
{
$param1 = mysql_real_escape_string ($_REQUEST["something1"]);
$param2 = mysql_real_escape_string ($_REQUEST["something2"]);
....
....
$sql = "insert into sometable (something,somethingelse) values('$param1','$param2')";
mysql_query($sql);
}

另外看看 smarty 或其他模板引擎。从长远来看,将 html 与 php 分开可以节省很多白发。

From what I see in the code the editor should load properly.

First - you are missing a </form> tag. It should work almost all the time without it but just in case.
Second - you are missing input names.
Third - you are missing submit button.
Fourth - you are missing some code to process the submit

This piece of code should look like

if($_REQUEST["sumbit"] == "somevalue")
{
$param1 = mysql_real_escape_string ($_REQUEST["something1"]);
$param2 = mysql_real_escape_string ($_REQUEST["something2"]);
....
....
$sql = "insert into sometable (something,somethingelse) values('$param1','$param2')";
mysql_query($sql);
}

Also take a look at smarty or other template engines. Separating html from php can save a lot of white hairs in the long run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文