dongyouzhui1969 2013-05-27 13:22
浏览 77
已采纳

在WordPress的get_results中出现致命错误

<?php

if (isset($_GET['confirm_code'])) {
    __construct();
}

function __construct() {
    global $wpdb;
    $table_one = $wpdb->prefix . "fantasticemailnewsletter_temp";

    $confirm = $_GET['confirm_code'];
    $mylink = $wpdb->get_results("SELECT * FROM $wpdb->$table_one WHERE confirm_code = $confirm");
    if ($mylink) {
        echo $mylink->confirm_code;
        echo "success";
        echo $wpdb->show_error();
    } else {
        echo "You Subscription is not process right now please try again later";
    }
}

?>

I’m trying to create a newsletter plugin in WordPress. I make a confirmation link for the corresponding subscriber to prevent spammers, creating a random key for every subscription e-mail. I pass the random key with query string through mail like this:

http://www.example.com/wp-content/plugins/plugininname/includes/subscriber.php?confirm_code=%2248c9c7d48165379b49f58962c0092466%22

In subscriber.php only, I’m using the above code, but for some reason, there’s an error at get_results():

Fatal error: Call to a member function get_results() on a non-object How can I overcome this prob.

  • 写回答

3条回答 默认 最新

  • duanfa0072 2013-05-27 13:33
    关注

    you dont need to redeclare wpdb in query $wpdb-> as you already declared in this line $table_one = $wpdb->prefix . "fantasticemailnewsletter_temp";

        <?php 
       if(isset($_GET['confirm_code'])) {
    __construct();
    }
    function __construct() {
    global $wpdb;
    
            $confirm = $_GET['confirm_code'];
            $mylink = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}fantasticemailnewsletter_temp WHERE confirm_code = $confirm");
            if($mylink) {
            echo $mylink->confirm_code;
            echo "success";
            echo $wpdb->show_error();
            }
            else {
            echo "You Subscription is not process right now please try again later";
            }
            }
                ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试