I am currently working on a small task that store a plugin information into database, but I have problem regarding to include the file that has the functions to run the query.
Here is the line that includes the file:
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
but I got the following when I run the code:
Warning:
require_once(ABSPATHwp-admin/includes/upgrade.php)
: failed to open stream: No such file or directory in/home/najam/dev/project1/wordpress/wp-admin/admin-insert.php
on line 18
I searched a lot but can’t find anything useful or helpful.
EDIT
Here is my code:
global $wpdb;
$table_name = $wpdb->prefix . 'table_form';
$sql = "CREATE TABLE $table_name (
id int(11) NOT NULL AUTO_INCREMENT,
rows int(11) DEFAULT NULL,
cols int(11) DEFAULT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta( $sql );`
5 Answers
insert.php
file that I made myself, actually I am new to wordpress,
I want to that is there any mistake that i am making? Actually I want
to store a plugin form information in the database.
Your question is very light on detail but I suspect that the mistake you are making is loading a file in such a way as it loads outside the context of WordPress, or in such a way that only parts of WordPress get loaded.
The lack of detail in your question– the near complete lack of context for the code– makes it impossible to provide a solid answer but I am leaning toward suggesting that you need to run your code via the AJAX API (even if not strictly AJAX). Something like this: https://wordpress.stackexchange.com/a/108145/21376
If you want a better answer, you must write a better question. Please click the “edit” button under your question and add as much detail as you can, but keep it organized.