wp custom plugin db insert data

I am trying to develop a custom plugin in word-press. I have created a form which calls the following script:

<?php
global $wpdb;
$sql="insert into wp_wbp_unpublished values(null,'".$_POST['bibkey']."',
'".$_POST['author']."','".$_POST['title']."','".$_POST['date']."','".$_POST['note']."',
'".$_POST['keywords']."','nothing');";
echo $sql;
//$wpdb->show_errors();
$wpdb->insert("wp_wbp_unpublished",array('uid'=>null,'pid'=>$_POST['bibkey'],
'author'=>$_POST['author'],'title'=>$_POST['title'],'year'=>$_POST['date'],
'note'=>$_POST['note'],'keyword'=> $_POST['keywords'],'abstract'=>"null"));
$wpdb->query($sql);
//$wpdb->print_error();
?>

As you can see, I have tried two different ways to insert data into my db but nothing worked.
The sql string is correct, I have checked it. But something wrong with the insert()/ query() commands. Any suggestions of what is wrong?

Related posts

Leave a Reply

3 comments

  1. Honestly, I do not see anything wrong with your code. At the end of the day I always blame WordPress for the fact that it sucks asshoe. I am having the same issue, except only after the user logs into the index file and tries to make changes to db. Why hasn’t anyone answered this question? Wtf

  2. You have to remove semicolon(); in your custom or first insert query

    $sql="insert into wp_wbp_unpublished values(null,'".$_POST['bibkey']."',
    '".$_POST['author']."','".$_POST['title']."','".$_POST['date']."','".$_POST['note']."',
    '".$_POST['keywords']."','nothing');";
    

    And other thing is when you make plugin, then you have to put “upgrade.php” file in you function…
    I hope it will work.