Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将空值插入wordpress数据库_Php_Mysql_Wordpress - Fatal编程技术网

Php 将空值插入wordpress数据库

Php 将空值插入wordpress数据库,php,mysql,wordpress,Php,Mysql,Wordpress,我的表格是这样的: <div id="titlewrap"> <label class="" id="title-prompt-text" for="title">Enter title here</label> <input type="text" name="title" size="30" value="" id="title" autocomplete="off"> </div> <br class="cl

我的表格是这样的:

<div id="titlewrap">
    <label class="" id="title-prompt-text" for="title">Enter title here</label>
    <input type="text" name="title" size="30" value="" id="title" autocomplete="off">
</div>
<br class="clear">
<?php
    $mva_content = '';
    $editor_id = 'editor';
    $settings = array('media_buttons' => false);
    wp_editor($mva_content, $editor_id, $settings);
?>
<form action="admin.php?page=list" method="post">
    <div id="poststuff">
        <div id="post-body">
            <div id="post-body-content">
                <div id="titlediv">
                    <div id="titlewrap">
                        <label class="" id="title-prompt-text" for="title">Enter title here</label>
                        <input type="text" name="title" size="30" value="" id="title" autocomplete="off">
                    </div>
                    <br class="clear">
                    <div id="wp-editor-wrap" class="wp-core-ui wp-editor-wrap html-active"><link rel='stylesheet' id='editor-buttons-css'  href='http://localhost/plug/wp-includes/css/editor.min.css?ver=4.0.5' type='text/css' media='all' />
<div id="wp-editor-editor-tools" class="wp-editor-tools hide-if-no-js"><div class="wp-editor-tabs"><a id="editor-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">Text</a>
<a id="editor-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">Visual</a>
</div>
</div>
<div id="wp-editor-editor-container" class="wp-editor-container"><textarea class="wp-editor-area" rows="20" autocomplete="off" cols="40" name="editor" id="editor"></textarea></div>
</div>

                    <p class="submit">
                        <input type="submit" name="create" id="create" class="button button-primary" value="Add New Video Ad">
                    </p>
                </div>
            </div>
        </div>
    </div>
</form>
单击“保存”按钮后,我想保存到我的wordpress数据库:

global $wpdb;
$title = $_POST["title"];
$content = $_POST["editor"];
$wpdb->insert("mytable", array(
   "title" => $title,
   "content" => $content,
)); 
我看到数据库中有一行的
id
递增,但
title
content
列中的值为空

我试着用字符串代替
$\u POST
变量,效果非常好

我的代码有错误吗

print\r($\u POST)
。这些值是否已进入脚本

快试试这个

注意:我已将%s添加到插入的末尾


准备好的报表


研究如何使用事先准备好的语句。(无论如何,您都应该使用它们。)

准备好的语句示例

$metakey    = "Harriet's Adages";
$metavalue  = "WordPress' database interface is like Sunday Morning: Easy.";

$wpdb->query( $wpdb->prepare( 
    "
        INSERT INTO $wpdb->postmeta
        ( post_id, meta_key, meta_value )
        VALUES ( %d, %s, %s )
    ", 
        10, 
    $metakey, 
    $metavalue 
) );

PHP
仅在服务器上运行,而表单将在用户浏览器中运行。浏览器中的
HTML
是什么样子的?也就是说,你能不能像浏览器接收到的那样显示完整的
部分(你可以使用浏览器中的“查看页面源代码”来查看它,而不使用
PHP
)。@stvcisco:我用完整html表单的源代码编辑了这篇文章。实际上,我不认为这是根本原因,因为如果我使用像
“testtitle”
这样的字符串而不是
$\u POST[“title”]
,它会工作!!我试着解除昏迷,问题总是在这里。但是添加到插入末尾的%s非常有效!谢谢!很高兴我能帮忙。:)
$metakey    = "Harriet's Adages";
$metavalue  = "WordPress' database interface is like Sunday Morning: Easy.";

$wpdb->query( $wpdb->prepare( 
    "
        INSERT INTO $wpdb->postmeta
        ( post_id, meta_key, meta_value )
        VALUES ( %d, %s, %s )
    ", 
        10, 
    $metakey, 
    $metavalue 
) );