You have a problem with your code formatting and syntax at the very least:
function ref_access(){
global $error;
if (is_user_logged_in()) // <-- problem here...
$newdb = new wpdb( 'user', 'pass', 'db', 'localhost' );
global $newdb;
$hf_username = wp_get_current_user();
$inputValue = $_POST[$quanid];
$wpdb->insert(
$table,
array(
'ItemID' => $quanid
'Price' => $inputValue
'user' => $hf_username
),
);
{ // <-- problem here...
}else {
$error = "Error: You must be logged in to submit prices";
return ;
}
}
Correctly formatted:
function ref_access(){
global $error;
if ( is_user_logged_in() ) {
global $newdb;
//you are not using $newdb anywhere in this functions
$newdb = new wpdb( 'user', 'pass', 'db', 'localhost' );
$hf_username = wp_get_current_user();
$inputValue = $_POST[$quanid];
//you need to delcare global $wpdb here if you plan to use $wpdb instead of $newdb
$wpdb->insert(
$table, //there is no $table variable within this function
array(
'ItemID' => $quanid
'Price' => $inputValue
'user' => $hf_username
)
);
} else {
$error = "Error: You must be logged in to submit prices";
return;
}
}
Update:
With regards to your comment about $table
being defined in another function, you need to then pass the valuue $table
to your function call ref_action('my_table_name')
.
Example:
function ref_access($table="") {
//function code
}
//Usage
ref_access('my_table_name');