Please take a look at the Codex to see how to prepare
your statement:
// Example straight copy-paste from Codex
$metakey = "Harriet's Adages";
$metavalue = "WordPress' database interface is like Sunday Morning: Easy.";
$wpdb->query( $wpdb->prepare(
"
INSERT INTO $wpdb->postmeta
( post_id, meta_key, meta_value )
VALUES ( %d, %s, %s )
",
10,
$metakey,
$metavalue
) );
Try this with your code too (it’s about security).
Related Posts:
- $wpdb->get_row() only returns a single row?
- WordPress 4.8.1 uses mysql_connect which doesn’t work with PHP 7
- How to use $wpdb to delete in a custom table
- Matching database content types to PHP types
- Does $wpdb->prepare not create a prepared statement that I can execute multiple times?
- $wpdb->last_error doesn’t show the query on error
- Saving custom form data into database
- Get data from database table by post_id to get data from second database table
- Delete/replace img tags in post content for auto published posts [closed]
- $wpdb sql help. Select post id and post meta value based on 2 other post_meta values
- $wpdb prepared with search term
- What does wp_update_post() do that the $wpdb class does not?
- wpdb-> not adding prefix to custom table
- $wpdb prepare issue with mysql DATE_FORMAT
- How-To: wpdb Insert Record With Date
- Get random row from custom table
- store custom WP table names in a global variable
- I want to update my postcontent with $wpdb
- How to save html and text in the database?
- XOR functionality for meta_query
- $wpdb->replace / Replace or update primary key
- Create an array with a string key from wpdb->get_results
- Replicating the WP_Query ‘s’ param with $wpdb
- get the number of queries made on a page(inside my plugin)
- Doing a loop with multiple DBs simultaneoulsy
- How can I migrate mysql_fetch_array to $wbpdb?
- What is _transient_random_seed for?
- WordPress SQL query – returning ‘true’ ‘false’ or ‘null’
- Modify the structure of data returned by $wpdb
- WPDB If primary key already exists, add +1 to integer field
- Foreach loop using $wpdb not results from rows
- How to get an array of user roles with or without a specific capability?
- Programmatically Creating Page using $wpdb and getting 404 error
- Return XML of Post Metadata
- Problem in inserting row to custom database table
- sanitize_text_field and apostrophe problem
- $wpdb->prepare with ON DUPLICATE KEY UPDATE
- 301 Redirect Code
- wpdb updating record in wordpress with json adds extra array elements
- How to display a specific category using a custom Query?
- Can’t pass variable in wordpress wpdb->get_results
- $wpdb->insert inserting only f character in custom table
- AWS Bitnami WordPress – SELECT command denied to user
- WPDB Placeholders and second argument for prepared statements
- PHP Fatal Error – $wpdb a non-object?
- Why does wpdb->update delete other meta?
- Increment integer field in database when WHERE needs to be dynamic [closed]
- Getting variable from Database
- How do I count columns on a custom WPDB query?
- Custom $wpdb returns unexpected time based results
- Trouble inserting string containing quotations marks with wpdb in save_post hook
- $wpdb->prepare was called incorrectly when inserting multiple records
- How to protect a script execution on WordPress?
- how to connect to another database in wordpress
- wpdb query not working
- Save sql file after doing insert wpdb
- Perform a function when a user clicks register button
- Can I use wpdb to insert query results into a post?
- WPDB Query Question with Category Only
- $wpdb->prepare error after WordPress update [duplicate]
- $wpdb->num_rows doesn’t work
- $wpdb->get_var next var?
- How do I modify this wpdb query to include posts that have a post_status of publish and draft?
- Can’t find out why dbDelta dosen’t create my table
- How to pass an input value into wpdb->Prepare
- Limit left join
- Check if Value Exists in Database, adding row details to variables and echoing result
- wpdb replace returning 1 where delete and insert is expected
- wpdb discards duplicate column names?
- update_post_meta not working in template_redirect action
- Get records from Formidable Table using $wpdb->get_col
- WPDB SQL query SELECT from category
- How to work with constraints on wordpress user metadata?
- How to Update multiple rows using $wpdb->update
- Unable to use $wpdb in WordPress
- How to display specific data from custom database table in WordPress
- Get 3 row ID’s via ARRAY_A
- Getting record from three wpdb tables
- Missing argument 2 for wpdb::prepare() [duplicate]
- Why is an empty result an error? ( $wpdb->get_row )
- get_row returns empty when data exists
- wpdb->update update the entire table instead of one row
- wpdb insert working in one function, but not another
- How to set up prepared query using IN statement
- Save customizer default values to DB on theme activation
- Plugin with connection to database – Single function
- Alter the main search query to search posts by coauthor user name
- WPDB Prepared Delete
- wpdb select from using array as search parameters
- wpdb Cannot Access Associative Array Data in a Count Query
- Using $wpdb to update current post
- Can’t get expected result from a wpdb query
- Can’t seem to get set_blog_id working, it just doesn’t reset the blog ID
- selecting row using wpdb which contain special symbols
- Query Problem in Clustom Plugin
- How does $wpdb->get_var work with offset?
- query_vars doesn’t return query string (trying to get data from $wpdb)
- Table wont load into WPDB
- WPDB prepare – like % – placeholders?
- $wpdb->prepare UPDATE process not work in functions.php