2014-02-19 3 views
0

내 플러그인을 통해 WordPress 데이터베이스에 데이터를 삽입하는 데 문제가 있습니다. 내 플러그인은 간단한 코드를 사용하여 계산이 이루어진 양식을 표시 한 다음 해당 정보가 데이터베이스에 삽입 될 것으로 예상되지만이 메시지가 표시됩니다.WordPress 데이터베이스에 삽입 - 멤버 함수 호출 insert()

나는 작동하지 않는 것 같은데?. 어떤 도움이 크게 감사하겠습니다. 삽입에 사용

플러그인 CODE :

include_once($_SERVER['DOCUMENT_ROOT'].'/wp-config.php'); 
$wpdb->insert(
    'wp_wine_bookings', 
    array(
     'name' => $_POST['name'], 
     'last_name' => $_POST['lname'], 
     'phone_number' => $_POST['phone_num'], 
     'email' => $_POST['email'], 
     'booking_status' => "Booked", 
     'tour_name' => $_POST['tourname'], 
     'tour_date' => $_POST['tourdates'], 
     'number_of_people' => $_POST['num_ppl'], 
     'price' => $_POST['priceget'], 
     'state' => $_POST['state'], 
     'city' => $_POST['city'], 
     'country' => $_POST['country'], 
     'mobile' => $_POST['mobile'], 
     'preffered_pickup_point' => $_POST['locationpickup'], 
     'arrival_date' => $_POST['arrivaldate'], 
     'name_on_credit_card' => $_POST['cn'], 
     'credit_card_type' => $_POST['type'], 
     'payment_date' => date("d-m-y"), 
     'occasion' => $_POST['occasion'], 
     'requirementsO' => $_POST['requirementsO'], 
     'requirementsP' => $_POST['requirementsP'] 
    ), 
    array( 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s', 
     '%s' 
    ) 
); 

PHP 오류 :

Fatal error: Call to a member function insert() on a non-object in /home/user/public_html/wp-content/plugins/BookingWT/booknow.php on line 52

+0

귀하의 오류가 자기 설명입니다 : 함수 삽입() 객체 $의 wpdb에 존재하지 않습니다. $ wpdb는 어디에 설정되어 있습니까? – skrilled

답변

2

첫째 :이 파일 wp-config.php을 포함 한 이유는
? 당신은 이것을 전혀 포함 할 필요가 없습니다. 둘째

:

당신은 wpdb 클래스 ($wpdb)의 인스턴스를 액세스하는. 어떤 로컬 범위에 있습니다.

당신은 $wpdbglobal을해야 :

global $wpdb;  // <--- making $wpdb as global 
$wpdb->insert(
... 
...