Two things, at least: It looks like you need to declare the global $wpdb
and you’re using $wpdb->insert()
incorrectly. The insert()
method doesn’t take your SQL query but a list of variables. It then create the SQL for you. See here
You can execute SQL directly but it’s a different process.
Related Posts:
- Using wpdb to connect to a separate database
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- How to define composite keys with dbDelta()
- Inserting Post Meta From SQL
- Why does dbDelta() not catch MysqlErrors?
- What causes the “max_user_connections” warning on WordPress frontend?
- How to execute mulitple statement SQL queries using $wpdb->query?
- Database slowdown after update to 3.4.1
- wpdb_prepare with multiple or condition
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Advanced SELECT query with condtional statements
- Redirecting to old domain after migration website
- Create table from array with prepare
- WordPress running SQL query to update database from form
- Have working sql query… trying to adjust it to use $wpdb
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- Trouble running $wpdb->query() with last_insert_id
- Query Column of Specific ID from Database Table
- How to create more than one new wpdb object?
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- “BS_” rows in postmeta table
- Where is the HTML-handler part in the wpdb class?
- WordPress Database Query works in phpMyAdmin but not in the code
- insert data from a form:: Warning Empty query mysqli::query()
- How can I get $wpdb to show MySQL warnings?
- How To connect to the same WordPress database with different database user
- using same mysql user with many databases
- Uploading to WordPress Database
- Rename a table in MySQL
- How should I tackle –secure-file-priv in MySQL?
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Checking if Database Table exists
- Get error messages when $wpdb->insert() returns false?
- Connect to database using wordpress wp-config file
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- Does wpdb add considerable overhead on queries with large result sets?
- Is it possible to define two databases for one installation?
- Hook into $wpdb
- Display data from a non wordpress database on a page template
- Connecting to external oracle database
- Huge wp_options table
- “MySQL server has gone away” since update to 3.8
- Can’t save ajax value to database
- Updating all rows of table with $wpdb
- Is $wpdb->prepare escaping to much? How to use it properly?
- Can I transfer a mysql database to another site?
- MySQL Syntax Error upon restoring database from backup [closed]
- Help running a MySQL query to update all wp_#_options tables in a Multisite install
- Remove database entries where post_date > expiration date
- Is it safe to convert tables from MyISAM to InnoDB?
- Emojis getting converted to “?”
- How to use a different database to list and manage comments in the backend
- How do I properly update the WordPress database password?
- $wpdb->insert is not working
- WordPress Install and Database on separate hosting?
- wpdb custom post_type problem
- In what part of the WordPress core does the users table and usermeta table get joined?
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- Using GROUP CONCAT in my-sql query with wp_usermeta table
- Help With MySQL to WPDB Query Conversion
- How to prevent/delay MySQL connections when an object cache is used?
- Migrating from PDO using SQLite to clean new install using MySQL
- $wpdb->insert Giving duplicates
- Duplicated site isn’t recognized as a site
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- Changing root password in PHPMyAdmin for WordPress Database when going live
- How to properly check if a table exists in WordPress Database using Show Tables Query
- Can’t update WordFence Options, clear data manually
- How to fetch records from database WordPress
- How and where is wordpress adding mySQL content to database?
- Best practice to import user base (subscribers) from one website to another?
- AJAX wp-mysql running too slow
- How to delete a particular row in a database table
- Should I use an additional column in the DB?
- Remote database -> massive response time increase?
- access JSON results from wordpress database with wpdb
- Getting value from database table depending on field value
- Getting “Error Establishing a Database Connection” on localhost in new Mac OSX Lion environment
- wpdb->insert not inserting first variable
- Cloning blog to localhost via WAMP
- How do I have a user upload a blog post and then retrieve that to display in a card on the site?
- How do I get database rows from a custom table using wpdb?
- How to edit custom table data in frontend
- local wordpress broke after changing URL
- Exporting Post ID, Post Title, Primary Category and Primary Category ID
- Help posting values to DB on submit using $wpdb->query
- How to create index (sql) to a meta_key?
- 2 $wpdb queries causing error Table ‘wp_postmeta’ is specified twice, both as a target for ‘UPDATE’
- WPCLI search and replace in a particlar site dir effect another site-dir
- Accessing content from third party as native posts in WordPress
- Hang Up Followed By Can’t select database
- Why is converting my database to UTF-8 truncating entries?
- Pulling values from a sepcific row in table
- Inserting into data into external DB using WPDB
- Insert Extra fields added in the front end registration form to DB
- export individual posts to text files or a single csv file
- $wpdb->insert not working for last select option