0

致命错误:在第 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 "); 

有人可以帮忙吗??

4

1 回答 1

3

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

global $wpdb;
于 2012-12-29T02:30:03.227 回答