0

Hello I am working on a template where I have to grab some value and insert them in my own created table in wordpress database. Now as I dont know how to insert record in wordpress database , so i am trying it on my local server for practice. my temlate file is:

<?php
/**
   Template Name: Injection.
 */
get_header();
?>
<form method="post" action="">
Album: <input type="text" name="album" />
Artist: <input type="text" name="artist" />
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['submit']))
{
require_once('../../../wp-load.php');
 global $wpdb

 $album=$_POST['album'];
 $artist=$_POST['artist'];

 $wpdb->insert( 'music', array( 'album' => $album, 'artist' => $artist ), array( '%s', '%s' ) )
}
?>

and here I have a strange problem If I dont use $wbdb class here then my temlate file data show on front end but when I used $wpdb for insertion then it show nothing on front end.

So do you have any suggestion for what should I do for Insert data in mysql.

Thanks

  • 1
    Not show nothing due the parse error 'global $wpdb' - no ';' at the end of line... – Oleg Butuzov Oct 22 '13 at 10:54
  • yes you were right... :) – Dk-Macadamia Oct 22 '13 at 11:23
1
#require_once('../../../wp-load.php');
#global $wpdb

Comment those lines.. you don't need it. $wpdb quite global in any template file.

BTW, do you really want's to make such form in your tempalte file? 0_o

  • no just test to insertion in wordpress – Dk-Macadamia Oct 22 '13 at 11:21
  • I am new in wordpress and I required these type info...so +1 – Dk-Macadamia Oct 22 '13 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.