First, you don’t need connection info when using the global $wpdb
. It’s already connected.
Second, if your insert is failing, then the first thing to check would be your data format. If you don’t specify a format, then it is handled as a string. See the docs for WPDB::insert
:
An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. A format is one of ‘%d’, ‘%f’, ‘%s’ (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
So if your table specifies a specific format required for the column, it may fail if your insert data format doesn’t match the requirement.
Related Posts:
- How to return number of found rows from SELECT query
- Check if post of title already exists
- $wpdb->delete column values IN ARRAY()?
- How To Make Connection To WordPress Data Base In A Plugin?
- Changing user_nicename
- Does WordPress cache get_user_meta() results?
- WordPress will not operate correctly
- How to Join two tables from separate databases within WordPress
- error importing localhost export file to server
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- How to sort results from a custom database table
- How can I call a row of user specific data from a custom table added to the WP Database
- How to merge local and live databases?
- How to track a users progress through pages by inserting data into WordPress Database?
- Import 10,000 Users into WordPress WITH a specific ID for each user
- WP database error for comments_popup_link()
- if statement on database query
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- No wp-config.php file on local install of wordpress – site still displays
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- Different database query in function.php using mysqli
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- Create WP_Query to search for posts by their categories or their parent/child categories
- WordPress not reflecting changed of the database
- How can I save unique user data on my site? [closed]
- Update results, Before deleting the related category [closed]
- database sent to a JSON file
- inserting a post from an extern php file but post content doesn’t show on wp site
- Using custom tables for old posts
- Not connecting to database in file with multiple MySQL connections
- WordPress Block developer from exporting Database via PHP
- wpdb prepare insert table doesn’t work
- Should I use WordPress to skin a database website?
- How do I display offsite database info on my wordpress site?
- Creating Database Table vs. Adding MetaData to Post & User
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- Most commented posts by time period (last 12h, last 24h and etc)
- I can’t update my data through $wpdb
- Why when I create a new post I found 2 record related to this post into the posts database table?
- Adding data to custom wordpress database table
- phpMyAdmin error #1062 – Duplicate entry ‘1’ for key ‘PRIMARY’
- Add row to custom database Table and delete all rows older than 1 day
- select a single val though a table in wordpress
- SQL error with custom query
- Please help! I have a problem with getting wordpress databas
- Error establishing a database connection (Set-up locally)
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- Using wpdb to connect to a different database is not working
- Insert data from form to database
- can’t delete a row from post_meta table
- How to set max users to 17.000
- two wordpress sites, two themes, one database, same content
- Insert double entry in DB
- How to connect database table to each registered wordpress user.
- Let users register weight each day and save it in DB
- MySQL database migration to WordPress
- Custom query_posts() parameter
- How to pass username into form that sends data to database
- How to edit the default database of WordPress [closed]
- Display total count of products in orders of a specific order status
- Execute multiple PHP Snippets causes error?
- Custom form that stores data in mysql database
- Putting form result in my database
- Can’t insert into a database wordpress
- How to validate WordPress generated password in DB using PHP?
- Custom query to get post names beginning with a digit
- the_author_meta not working
- #1062 – Duplicate entry ‘1’ for key ‘PRIMARY’
- mysqli_real_connect() – authentication method unknown to the client Warnings
- Prevent Data Resubmission On Page refresh
- SQL QUERY – Select a value directly from the database
- Getting id of poll from WP database
- I want to select the from values from database in WordPress? [closed]
- SQL Injection blocked by firewall
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Long running queries
- Custom array from a query only write the last row of the query
- Use $wpdb or other PHP script method to find/replace in WP database
- Issue with fetching mysql data and displaying results via shortcode in webpage
- Custom route and query
- How do I make this Metabox show current DB value?
- Edit Account – read and write to MySQL
- mySQL queries are executed twice on wordpress website
- Most viewed posts in WordPress
- Weird fonts showing which are coming from database
- wp_update_post gives 500 internal error
- WordPress Bad Request Error 400
- I am facing this error Your PHP installation appears to be missing the MySQL extension which is required by WordPress
- cant insert data in a custom table in phpmyadmin
- autocomplete in wordpress using ajax with json-data
- wp-login.php?redirect_to=https problem
- Query doesn’t display text data with apostrophes
- SQL Query Search page
- Accessing external database: ERR_INCOMPLETE_CHUNKED_ENCODING
- AJAX Not Working With WordPress Database properly
- Manipulate database of WordPress site with my own scripts
- Problems with plugin that fetches data from database with ajax
- Insert into db with foreach problem
- Your PHP installation appears to be missing the MySQL … After deleting and restarting from cpanel
- running an existing WordPress site from Visual Studio Code?