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?
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
You have to remove semicolon(); in your custom or first insert query
And other thing is when you make plugin, then you have to put “upgrade.php” file in you function…
I hope it will work.
I have used the following solution, which seems to be the best:
For instance:
More information: https://codex.wordpress.org/Class_Reference/wpdb#INSERT_row