I have a table named ‘species’ with 3 columns: id, specie, rate.
And I have tried using the following query but it throws the errors:
Fatal error: Uncaught Error: Call to a member function insert() on null in D:Wordpress....includesspecie_form.php on line 10
Error: Call to a member function insert() on null in D:Wordpress.....includesspecie_form.php on line 10
Query
$specie_name= $_POST['specie_name'];
$specie_rate=$_POST['specie_rate'];
global $wpdb;
$wpdb->insert('species', array( //this is line 10 of error
'id' => NULL,
'specie' => '$specie_name',
'rate' => '$specie_rate'
));
2
Answers
Ok so I managed to solve the issue by including some needed files like so:
it look like in table species you cannot enter null as a valid value to id column .
look in the table if column id is nullable or not
and try to give him a number
if there is an autoincrese option try insert without the id column
this is not the problem with the query but how you access wpdb see
Call to a member function insert() on null WORDPRESS