This error:
Fatal error: Call to a member function insert() on a non-object
Means that $wpdb
isn’t instantiated so you are running your code too early or out of WordPress context– for example, in an exterior PHP file accessed directly, which is what I suspect (Poorly conceived AJAX request perhaps?).
As mentioned, the code has more formats that data elements and your single quotes are going to cause this fail (in a sense) anyway as you will literally be inserting “$email” and “$name” strings into the database.
function insert_record_to_db($name,$email,$dis){
global $wpdb;
$tablename = $wpdb->prefix.'complaint';
$data=array(
'name' => $name,
'email' => $email,
'dis' => $dis
);
$format= array('%s','%s','%s');
$wpdb->insert( $tablename , $data , $format );
};
insert_record_to_db('a','b','c');
Related Posts:
- Get error messages when $wpdb->insert() returns false?
- Detecting errors generated by $wpdb->get_results()
- $wpdb->prepare() warning in WordPress 3.5
- What causes the “max_user_connections” warning on WordPress frontend?
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- $wpdb doesn’t like to store arrays
- Does dbDelta delete columns as well?
- wpdb update add current timestamp not working
- WordPress Unit Testing – Cannot Create Tables
- Why does $wpdb return strings for mysql integer values?
- Inserting data into custom tables
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- Export wordpress table to excel
- When importing database, it shows error
- How to close wpdb connection? [duplicate]
- Inserting Post Meta From SQL
- Why does dbDelta() not catch MysqlErrors?
- Strange Deadlock database error for the query “Delete From wp_options”
- WordPress showing install screen after max_questions error
- Safe way to find last inserted id in a table?
- Database slowdown after update to 3.4.1
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- error establishing a database connection
- Get data from database using $WPDB
- Getting all the users who have author privilege
- Multiple postmeta with same name for one post in wp_postmeta table
- WP Database Table to CSV file
- Cannot update custom database table row
- Error: SELECT SQL_CALC_FOUND_ROWS
- Modify Database in Multi-Site wp_usermeta table
- Where are WP_Errors Saved
- Advanced SELECT query with condtional statements
- Select two sums with single get_var statement
- Error establishing database connection – high traffic?
- WordPress choose wrong database
- Redirecting to old domain after migration website
- Catalina an MAMP Database Conenction Error
- Does WordPress $wpdb functions wait when table is locked?
- Trouble Migrating all data blog from WordPress.com to WordPress.org
- How Can I Put Meta_Compare in the Database-Query?
- WordPress running SQL query to update database from form
- How to fix database error duplicate entry
- I’m not able to get access to $wpdb [duplicate]
- WPDB SQL query with prepare() returning variable, not db value
- $wpdb error (Call to a member function insert() on a non-object)
- Moving to another server database connection error [closed]
- “Error establishing a database connection” – Intermittent error on GoDaddy
- Is it important to have integers inserted using %d rather than %s?
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- How can I restrict php mail() to only send me one email after a db error
- CreateOrUpdate in WordPress
- Clear Terms from Taxonomy for Specific Post IDs?
- Global__r connection timed out
- Trouble running $wpdb->query() with last_insert_id
- How to get a list of WordPress default database tables?
- Using $wpdb | checking entered email against existing emails in db
- Optimizing function that automatically creates internal links based on post title string
- How to connect and insert data in database of wordpress?
- Get results from wordpress data custom table
- Outputting query results
- WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version [closed]
- add_post_meta — not working
- Select From wpdb – Author/User Directory page
- Creating and Using Tables in the WordPress Database
- Error establishing a database connection in wordpress site , website not opening
- $wpdb->insert not inserting all rows
- wpdb Insert unknown post data dynamic foreach loop
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to get the full stack trace for WordPress “table doesn’t exist” error in debug.log?
- How to insert a value to decimal type field using wpdb->prepare?
- Insert NULL value using prepare()
- I imported an restore an database and It shows #1067 – Invalid default value for ‘user_registered’
- Help with $wpdb on custom code
- “BS_” rows in postmeta table
- SQL database import #1046 error
- $wpdb->insert duplicating rows
- How to rerieve comments and their replies from DB
- Can I use a wpdb object to connect to a non-WordPress Oracle database [duplicate]
- Where is the HTML-handler part in the wpdb class?
- error establishing a database connection 3
- WordPress Database Query works in phpMyAdmin but not in the code
- “wordpress error in establishing database connection” and missing tables
- Correct and secure way to access a custom SQL database in a custom PHP template file
- About wp database hooks (error establishing connection)
- Using $wpdb to insert data into a table
- How To connect to the same WordPress database with different database user
- Call to a member function insert()
- I have include wp-config, should I add global $wpdb also?
- Catchable fatal error in formatting.php
- Processing a lot of $wpdb isn’t insert all the data
- Can’t Install WordPress (local) Failed to open file wp-includes/wp-db.php
- Restoring .sql backup results in “Error establishing a database connection”
- How can I retrieve data from alternate database using wpdb class?
- Creating Tables in WordPress Database
- Print output of Table Creation
- How to use remote db tables in current config? [duplicate]
- $wpdb->prepare returns empty array
- How to delete field using WPDB?
- Uploading to WordPress Database