0
嗨,我有一个简短的代码在这里插件开发。我一直在尝试不同的方式,以便在** textarea ****中显示**结果。问题是它没有出现在textarea中。没有错误只是空白。我究竟做错了什么?这是我的代码?希望得到快速的回应。函数调用时不显示结果
<?php
add_action('admin_menu','hello_world_plugin');
function hello_world_plugin(){
add_options_page('Hello Page','Hello Submenu','manage_options',__FILE__,'Hello_Admin');
}
//Insert Data
global $wpdb;
$first = $_POST['firstname'];
$last = $_POST['lastname'];
if(isset($_POST['Submit'])) {
$wpdb->insert("wp_options", array(
"option_name" => $first,
"option_value" => $last
)
);
echo '<script language="javascript">';
echo 'alert("Data Submitted!")';
echo '</script>';
}
?>
<?php
function Hello_Admin() {
echo '<div class = "wrap">';
echo '<h4> Hello World Plugin </h4>';
echo '</div>';
echo '<form action = "" method = "POST">';
echo '<input type="text" name="firstname" placeholder="First Name">';
echo '<input type="text" name="lastname" placeholder="Last Name"><br><br>';
echo '<input type = "submit" name = "Submit" value ="Submit to (wp_options)" class = "button-primary"><br><br>';
echo '<input type = "submit" name = "Display" value ="Display Data from (wp_options)" class = "button-primary"/><br><br>';
display();
echo '</form><br>';
}
function display(){
?>
<textarea cols="50" rows="15">
<?php
global $wpdb;
if(isset($_POST['Display'])) {
$result = $wpdb->get_results (
"
SELECT * FROM wp_options
WHERE option_id = '262'
"
);
print_r($result);
}
?>
</textarea>
<?php
}
?>