tags:

views:

28

answers:

1

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  A: 

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.

Dwayne
Technically you're right on the $_REQUEST thing, though its not wordpress and its not merging per se. $_REQUEST is a PHP super global that contains _GET, _POST and _COOKIE. Here's the link to the manual http://www.php.net/manual/en/reserved.variables.request.php
dabito
Also, I would recommend using if($_POST['new_title']) as opposed to just using $_REQUEST if thats the method used in the form (which OP is using right now).
dabito
Also I would run `stripslashes()` on your POST'ed data, as WordPress (For some insane reason) enforces magic quotes.
TheDeadMedic
Actually, I was correct. If you look at the file wp-settings in the root Wordpress directory (where wp-config is located) lines 636 to 637 are the following:// Force REQUEST to be GET + POST. If SERVER, COOKIE, or ENV are needed, use those superglobals directly.$_REQUEST = array_merge($_GET, $_POST);So using $_REQUEST should work as required instead of $_POST or $_GET.
Dwayne