【问题标题】:Call to a member function insert() on a non-object with wpdb使用 wpdb 在非对象上调用成员函数 insert()
【发布时间】:2016-01-18 04:04:06
【问题描述】:

当它调用 mysave.php 文件时,我得到错误调用一个非对象上的成员函数 insert()需要放到根目录下。

<style>
form#my > #phase2{ display:none; }
</style>

<script>
function _(x){
    return document.getElementById(x);
}
function processPhase1(){
        _("phase1").style.display = "none";
        _("phase2").style.display = "block";        
    } 
function submitForm(){  
            _("myform").method = "post";
            _("myform").action = "mysave.php";
            _("myform").submit();
        }
</script>

        <form id="myform" onsubmit="return false" > 
         <div id="phase1">
        <input type="text" id="inputbook" name="bookname" placeholder="book name" height="34px">
        <button onclick="processPhase1()"><strong>Next</strong></button>
        <div>
        <div id="phase2">
        <input type="text" id="inputcode" name="code" placeholder="code" height="34px">
        <button onclick="submitForm()"><strong>SUBMIT</strong></button>
    <div>
        </form>

mysave.php

if(isset($_POST['bookname']))
{
    global $wpdb;
    $bookname=$_POST['bookname'];
    $code=$_POST['code'];
    $todaydate = new DateTime();
    $todaydate =$todaydate->format('Y-m-d H-i-s');
    $bookpost= array('post_type'=>'books',
                        'post_title'=>$bookname,
            'post_author'=>'1',
            'post_status'=>'publish',
            'post_date'=>$todaydate );
    $wpdb->insert('wp_posts',$bookpost); 
    $Cid=$wpdb->insert_id;
    update_field('code',$code,$Cid);
}

【问题讨论】:

  • 你能补充更多关于你的问题的信息吗?

标签: php jquery


【解决方案1】:

在您的 mysave.php 中创建一个模板。在您的页面上方编写此代码。

<?php
    /**
     * Template Name: Your template name
    */
?>

然后转到您的 wp-admin 面板创建新页面并从下拉列表中选择您的模板。

【讨论】:

    猜你喜欢
    • 2013-03-11
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2010-09-26
    • 2012-04-20
    • 2015-05-01
    • 2014-08-07
    • 2013-12-01
    相关资源
    最近更新 更多