I am trying to interact with my wqordpress database.
I need to upload a csv file to my database but it will not run any query, no matter which way I try using the WordPress codex, I cannot get it to do what I need to.
So from my Admin panel, I upload the csv file click sumbmit which then runs the following function.
The error I get is: Fatal error: Call to a member function query() on a non-object in /home/dlaveric/public_html/client-area/clients/client/wp/wp-content/themes/Theme/includes/wine-list/wine-list-functions.php on line 11
Here is my code:
<?php
if (isset ($_POST['Submit']))
{
upList();
}
function upList(){
global $wpdb;
$wpdb->query(
$wpdb->prepare(
" DELETE FROM $wpdb->winelist"
)
);
if ($_FILES['csv']['size'] > 0) {
//get the csv file
$file = $_FILES['csv']['tmp_name'];
$handle = fopen($file,"r");
$data[]='';
//loop through the csv file and insert into database
do {
if ($data[0]) {
$wpdb->insert(
'winelist',
array(
'item' => addslashes($data[0]),
'btlPrice' => addslashes($data[1]),
'casePrice' => addslashes($data[2]),
'salePrice' => addslashes($data[3])
)
);
}
} while ($data = fgetcsv($handle,1000,",","'"));
$wpdb->get_results(
"
SELECT *
FROM $wpdb->winelist
ORDER by id
"
);
//throw out table stuff here!
}
}
?>