array key: run_query
returns mixed
The query callable is run either inserting or updating data and is the first step in the waterfall. If you want to do PHP or database validation it can be done here. A false return value might imply a successful query, it is the default. If there are errors the return value might hold information for the notices callable which follows.
function saturn_tables_cars_run_query($input_form, $query_return) { global $wpdb; if (isset($_POST['submit'])) { $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; foreach ($input_form as $key => $value) { if (isset($_POST[$key])) $post_vars[$key] = sanitize_text_field($_POST[$key]); } if ($id == 0) { //insert new row $data = array('make' => $post_vars['make'], 'model' => $post_vars['model'], 'mpg' => $post_vars['mpg'], 'cylinders' => $post_vars['cylinders'], 'weight' => $post_vars['weight'], 'model_year' => $post_vars['model_year'], 'country' => $post_vars['country']); $formats = array('%s','%s','%f','%d','%d','%d','%s'); if (count($wpdb->get_var("SHOW TABLES LIKE 'saturn_tables_cars'"))) { $query_return = $wpdb->insert('saturn_tables_cars', $data, $formats); return false; } } elseif ($id > 0) { //update row $data = array('make' => $post_vars['make'], 'model' => $post_vars['model'], 'mpg' => $post_vars['mpg'], 'cylinders' => $post_vars['cylinders'], 'weight' => $post_vars['weight'], 'model_year' => $post_vars['model_year'], 'country' => $post_vars['country']); $where = array('id' => $id); $data_formats = $formats = array('%s','%s','%f','%d','%d','%d','%s'); $where_formats = array('%d'); if (count($wpdb->get_var("SHOW TABLES LIKE 'saturn_tables_cars'"))) { $query_return = $wpdb->update('saturn_tables_cars', $data, $where, $data_formats, $where_formats ); return false; } } } }