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
}
?>