致命错误:在非对象上调用成员函数query()(wordpress 3..5)

时间:2012-12-29 02:24:11

标签: wordpress function php

致命错误:在第47行的/home/dbc/public_html/CEHPLearning/wp-content/themes/cehpLearning/page-password-reset.php中调用非对象的成员函数query()

    <div class="content-page">

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

        <div class="the-post-container">

            <?php if (!get_meta('hide_title')) : ?>
            <header class="entry-header">
                <!-- Title / Page Headline -->
                <h1 class="entry-title" title="<?php echo the_title_attribute('echo=0'); ?>"><?php the_title(); ?></h1>
            </header>
            <?php endif; ?>

            <!-- Page Text and Main Content -->
            <div class="entry-content clearfix">

                <?php
                $error = '';
                $success = '';
                $user_id = get_current_user_id();

                if(isset($_POST['task']) && $_POST['task'] == 'reset') {

                $password = $_POST['pwd1'];
                $con_password = $_POST['pwd2'];

                if($password == "" || $con_password == "") { 
                $error = 'Password field is required.'; 
                } else if($password <> $con_password){
                $error = 'Password does not match.';
                } else {
                    $qry = $wpdb->query("UPDATE $wpdb->users SET user_pass = '".md5($password)."' WHERE ID=$user_id "); 
                    if($qry) { 
                        $success= 'Password updated successfully, it will take effect in your next login.'; 
                    }
                }
                }
                ?>
                <?php the_content(); ?>
                <div class="pwChangeBox">
                    <form name="frmreset" id="frmreset" action="" method="post">
                        <h3>Don't like your password?<br/>
                        <span>Try a new one.</span></h3><br/>
                        <div class="msgBox"> <?php if($error != "") : echo '<p class="errormsg">'.$error.'</p>'; endif; if($success != "") : echo '<p class="successmsg">'.$success.'</p>'; endif; ?> </div>
                        <label>Password</label><br/>
                        <input type="password" value="<?php echo (isset($_POST['pwd1']) ? $_POST['pwd1'] : ''); ?>" name="pwd1" id="pwd2" /><br/> 
                        <br/>   
                        <label>Password Again</label><br/>
                        <input type="password" value="<?php echo (isset($_POST['pwd2']) ? $_POST['pwd2'] : ''); ?>"" name="pwd2" id="pwd2" /><br/>
                        <br/>
                        <button type="submit" class="alignleft" >SUBMIT</button>
                        <input type="hidden" name="task" value="reset" />
                    </form>
                </div>

            </div>

    </article>

</div>

有问题的一行是....

$qry = $wpdb->query("UPDATE $wpdb->users SET user_pass = '".md5($password)."' WHERE ID=$user_id "); 

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

您需要先调用全局$ wpdb实例。所以在你进行查询之前添加:

global $wpdb;