Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 );`
share|improve this question
4  
Where is this code? –  s_ha_dum Feb 14 at 5:32
2  
ABSPATH does not appeared to be defined. Where are you using it? –  Seamus Leahy Feb 14 at 5:34
    
You probably missed a trailing slash after the ABSPATH and before wp-admin/. Try this: ABSPATH . '/wp-admin/. And consider this StackOverflow WP Question also. –  Mayeenul Islam Feb 14 at 5:36
2  
What is the file /wp-admin/admin-insert.php? This is not in the core. Are modifying the WordPress core? –  Seamus Leahy Feb 14 at 6:07
1  
@Mayeenul Islam no, no trailing slash required after ABSPATH. ABSPATH variable already contains trailing slash... –  Shail Jun 14 at 11:10

3 Answers 3

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: http://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.

share|improve this answer
    
I'd be quite worried that a database table is being created inside an AJAX call fullstop –  Tom J Nowell Aug 15 at 1:04

You should not need the / but try a slash at the start of the /wp-admin

require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );

But did you check if /wp-admin/admin-insert.php file exists?

Is the ABSPATH defined? Add the following to check:

// Is ABSPATH defined?
if ( !defined('ABSPATH') )
die('-1');

Also, are you trying to run this without loading WP? Plus, you could try site_url() and work with it.

share|improve this answer

there is a nice WordPress function that helps you anytime you don't want to check for missing "/" on your path.

trailingslashit

your example should be the recommended way written:

require_once( trailingslashit( ABSPATH ) . 'wp-admin/includes/upgrade.php' );

using this function, you never have to put "/" in front of your "relative" path, as this function makes sure that "/" will be in case is missing.

this is why we have created that function in WordPress.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.