0
votes

I have already get how to insert in the database. My only problem is to get the value of text box to insert in the database. Here is my code:

function dbAdd() {
  global $wpdb; 
  $new_title = $_POST['new_title'];
  $new_author = $_POST['new_author'];
  $new_url = $_POST['new_url'];
  if($wpdb->insert('wp_podcast_data', array( 'mp3_id' => '', 'title' => '$new_title', 'creator' => '$new_author', 'url' => '$new_url') ))
  {
  echo"<h1>Save Successfully!</h1>";
  }else
  {
  echo mysql_error();
  }
  }
 ----------------------------------------------------------
function player_manager_index() {

if($_SERVER['REQUEST_METHOD']=='POST')
{
dbAdd();
}
?>
<h3>Podcast Player Manager (This Plug is not yet finish)</h3><br />
<p>Note: This Player Manager needs the URL of mp3 file that you want to include in your podcast player.</p>
<form method="post" action="">
<label for="new_title" style="display:block; padding-top: 5px; cursor: default;">Title</label><input type="text" id="new_title" name="new_title" size="50" />
<label for="new_author" style="display:block; padding-top: 5px; cursor: default;">Author</label><input type="text" id="new_author" name="new_author" size="50" />
<label for="new_url" style="display:block; padding-top: 5px; cursor: default;">URL</label><input type="text" id="new_url" name="new_url" size="50" />
<div><input type="submit" value="Add New" style="margin-left: 20px; margin-top: 15px;" /></div>
</form>

Please Help me. I'm newbie in wordpress. Thank you so much.

1
What's happening right now? Is there an error or is nothing happening? Also, I would check if $_POST is empty rather than checking the REQUEST_METHOD, as WordPress changes a lot of that type of data.Kerry Jones

1 Answers

2
votes

Correct me if I am wrong someone, but I could have sworn that Wordpress merges both the $_POST and $_GET variables into the one $_REQUEST variable. So if you replace all of your $_POST's with $_REQUEST instead you might find it will work.

In your player_manager_index function I wouldn't be using the following: if($_SERVER['REQUEST_METHOD']=='POST')

Replace that with: if($_REQUEST['new_title'])

So you are instead checking if a variable is being sent, as opposed to just permitting the function to run if it posted to.