简体   繁体   中英

Inserting SQL Data From Wordpress

I created a custom table in my WP database to collect some basic info, but I can't seem to get this function to insert. The table has the following columns, id, name, city, state, and product. The id is set as my primary key and is set to auto increment.

I'm not going to give the entire function, just the relevant insert portion. All the variables have been defined and the function itself does get called. Prior to adding the sql portion I called the function on a test page and had everything printed out.

Any help would be greatly appreciated. I'm trying to use the wordpress sql class.

$table = 'my_test_table';
    $data = array('name' => $name, 'city' => $city, 'state' => $state, 'product' => $product_name);  

    $wpdb->insert($table, $data);

Kaloyan pointed out I was missing:

global $wpdb;

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM