Insert into wordpress database - Call to a member function insert()

STiTCHiCKED

Im having an issue with inserting data into the wordpress database through my plugin. My plugin uses a shortcode to display a form from which some calculations are made and then that information is the then supposed to be inserted into the database but I end up getting this message.

I can't seem to get it to work?.. Any help would be appreciated greatly.

PLUGIN CODE used for the insert:

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 ERROR:

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

Rahil Wazir

First:
Why you have included the file wp-config.php? you don't need to include this at all.

Second:

You're accessing the instance of wpdb class ($wpdb). Which is in local scope.

You have to make $wpdb global:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

no matching member function for call to 'insert'

From Dev

Fatal error: Call to a member function insert() on a non-object

From Dev

No matching member function for call to "insert" std::unordered_map

From Dev

Call to a member function insert() on a non-object with wpdb

From Dev

Error Fatal error: Call to a member function insert() on a non-object

From Dev

PHP: Fatal error: Call to a member function insert() on a non-object

From Dev

No matching member function for call to std::unordered_map::insert()

From Dev

wordpress database call to a member error

From Dev

Call function in document insert

From Dev

Insert a dropdown list from database to wordpress page($.post is not function)

From Dev

No matching member function in Map insert

From Dev

Insert empty values to wordpress database

From Dev

Insert two row in wordpress database

From Dev

C++ Multimap No Matching Member Function Insert

From Dev

Can't insert hashed data to Wordpress database

From Dev

Unable to insert values into database using ajax call

From Dev

SQL Trigger on Insert to call a Function and Manipulate Values

From Dev

Insert JavaScript function (as string) into Html and call it

From Dev

How to call function without leaving insert mode?

From Dev

Call insert icon function in PowerPoint programmatically

From Dev

How to unit test a database insert function PDO

From Dev

PHP,PDO,MySQLi function dont insert to database

From Dev

How do i write a function to insert into database

From Dev

How do I insert a member-function pointer into a map?

From Dev

How do I insert a member-function pointer into a map?

From Dev

Insert data into Wordpress database table from a custom form

From Dev

insert form values to database table using wordpress 4.7

From Dev

fatal error: call to a member function delete() on a non-object wordpress

From Dev

Fatal error: Call to a member function getElementsByTagName() WordPress 4.2.2 RSS Feed

Related Related

  1. 1

    no matching member function for call to 'insert'

  2. 2

    Fatal error: Call to a member function insert() on a non-object

  3. 3

    No matching member function for call to "insert" std::unordered_map

  4. 4

    Call to a member function insert() on a non-object with wpdb

  5. 5

    Error Fatal error: Call to a member function insert() on a non-object

  6. 6

    PHP: Fatal error: Call to a member function insert() on a non-object

  7. 7

    No matching member function for call to std::unordered_map::insert()

  8. 8

    wordpress database call to a member error

  9. 9

    Call function in document insert

  10. 10

    Insert a dropdown list from database to wordpress page($.post is not function)

  11. 11

    No matching member function in Map insert

  12. 12

    Insert empty values to wordpress database

  13. 13

    Insert two row in wordpress database

  14. 14

    C++ Multimap No Matching Member Function Insert

  15. 15

    Can't insert hashed data to Wordpress database

  16. 16

    Unable to insert values into database using ajax call

  17. 17

    SQL Trigger on Insert to call a Function and Manipulate Values

  18. 18

    Insert JavaScript function (as string) into Html and call it

  19. 19

    How to call function without leaving insert mode?

  20. 20

    Call insert icon function in PowerPoint programmatically

  21. 21

    How to unit test a database insert function PDO

  22. 22

    PHP,PDO,MySQLi function dont insert to database

  23. 23

    How do i write a function to insert into database

  24. 24

    How do I insert a member-function pointer into a map?

  25. 25

    How do I insert a member-function pointer into a map?

  26. 26

    Insert data into Wordpress database table from a custom form

  27. 27

    insert form values to database table using wordpress 4.7

  28. 28

    fatal error: call to a member function delete() on a non-object wordpress

  29. 29

    Fatal error: Call to a member function getElementsByTagName() WordPress 4.2.2 RSS Feed

HotTag

Archive