<?php
if($_SERVER[‘REQUEST_METHOD’] == “GET”){
global $wpdb, $table_prefix;
$tableName = $table_prefix . “contact_ways”;
$id = $_GET[‘id’];
echo $id.”<br>”.$tableName.”<br>”;
$row = $wpdb->get_results(“SELECT * FROM $tableName WHERE id=$id”);
}
it retunes
1
contact_ways
Fatal error: Uncaught Error: Call to a member function get_results() on null in C:\xampp\htdocs\wordpress\wp-content\plugins\connectUs\state_action.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\wordpress\wp-content\plugins\connectUs\state_action.php on line 7
after that i try this
<?php
define(‘WP_USE_THEMES’, false);
global $wpdb;
require( ‘wp-load.php’ );
if($_SERVER[‘REQUEST_METHOD’] == “GET”){
global $wpdb, $table_prefix;
$tableName = $table_prefix . “contact_ways”;
$id = $_GET[‘id’];
echo $id.”<br>”.$tableName.”<br>”;
$row = $wpdb->get_results(“SELECT * FROM $tableName WHERE id=$id”);
}
it retunes
Warning: require(wp-load.php): failed to open stream: No such file or directory in C:\xampp\htdocs\wordpress\wp-content\plugins\connectUs\state_action.php on line 4
Warning: require(wp-load.php): failed to open stream: No such file or directory in C:\xampp\htdocs\wordpress\wp-content\plugins\connectUs\state_action.php on line 4
Fatal error: require(): Failed opening required ‘wp-load.php’ (include_path=’C:\xampp\php\PEAR’) in C:\xampp\htdocs\wordpress\wp-content\plugins\connectUs\state_action.php on line 4
How can i fix this?!
[ad_2]
What file is your code in and where is the file located? The way you’re loading wp-load.php means your file must be in the web root. If your code is located somewhere else then you need to change the path parameter in your require() call.