admin管理员组文章数量:1278910
The file path is: wordpress/wp-content/themes/neve/index.php
"index.php" content is:
<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM users WHERE username = 'Peter'");
foreach ( $result as $results )
{
echo $results->id.'<br/>';
echo $results->username.'<br/>';
echo $results->password.'<br/>';
}
?>
It works! But, when I change the content of the index.php, see below: New "index.php" content is:
<?php
header("Location: http://34.92.209.11/wp-content/themes/neve/Test_PHP.php");
?>
Then the content of the "Test_PHP.php" is:
<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM users WHERE username = 'Peter'");
foreach ( $result as $results )
{
echo $results->id.'<br/>';
echo $results->username.'<br/>';
echo $results->password.'<br/>';
}
?>
It does not work, and shows "HTTP ERROR 500", why??? Only the file name called "index.php" can access the database? I've been trying to find the answer. I really hope someone can answer me. Thank you so much!
The file path is: wordpress/wp-content/themes/neve/index.php
"index.php" content is:
<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM users WHERE username = 'Peter'");
foreach ( $result as $results )
{
echo $results->id.'<br/>';
echo $results->username.'<br/>';
echo $results->password.'<br/>';
}
?>
It works! But, when I change the content of the index.php, see below: New "index.php" content is:
<?php
header("Location: http://34.92.209.11/wp-content/themes/neve/Test_PHP.php");
?>
Then the content of the "Test_PHP.php" is:
<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM users WHERE username = 'Peter'");
foreach ( $result as $results )
{
echo $results->id.'<br/>';
echo $results->username.'<br/>';
echo $results->password.'<br/>';
}
?>
It does not work, and shows "HTTP ERROR 500", why??? Only the file name called "index.php" can access the database? I've been trying to find the answer. I really hope someone can answer me. Thank you so much!
Share Improve this question edited Nov 15, 2021 at 23:21 Tom J Nowell♦ 61k7 gold badges79 silver badges148 bronze badges asked Nov 15, 2021 at 22:50 Flicker LauFlicker Lau 11 bronze badge 2 |1 Answer
Reset to default 0In WordPress's template hierarchy, index.php
is the catch-all file for any WordPress post/page/archive/etc. that might get loaded. By the time the active theme's index.php
file is loaded, WordPress is already set up.
By redirecting from the theme's index.php
to another file, you're re-starting the page load from scratch. If you don't explicitly include certain WordPress files, then there are no WordPress functions, classes, etc. that will be loaded.
$wpdb
, in that case, is unset (NULL
, most likely), and your 500 error is most likely because you're trying to treat an unset NULL
value like an object.
本文标签: phpPlease help I have a problem with getting wordpress databas
版权声明:本文标题:php - Please help! I have a problem with getting wordpress databas 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741218525a2360516.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_header()
which would containwp_head()
to give you access to$wpdb
? Could you remove the image and add in actual, workable code, please? – Howdy_McGee ♦ Commented Nov 15, 2021 at 23:07