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:

   Template Name: Injection.
<form method="post" action="">
Album: <input type="text" name="album" />
Artist: <input type="text" name="artist" />
<input type="submit" name="submit"/>
 global $wpdb


 $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.


  • 1
    Not show nothing due the parse error 'global $wpdb' - no ';' at the end of line... Oct 22 '13 at 10:54
  • yes you were right... :) Oct 22 '13 at 11:23
#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 Oct 22 '13 at 11:21
  • I am new in wordpress and I required these type info...so +1 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.