Protect custom form from SQL injection

Yes, $wpdb->update is sufficient protection. You should not escape or prepare the data. From the documentation of wpdb: data (array) Data to update (in column => value pairs). Both $data columns and $data values should be “raw” (neither should be SQL escaped). This means that if you are using GET or POST data you may … Read more

Create Array from data in the OPTIONS table

$all_options = wp_load_alloptions(); $plugin_order_options = array(); foreach( $all_options as $name => $value ) { if(stristr($name, ‘plugin_order_’)) $plugin_order_options[$name] = $value; } print_r($plugin_order_options); In plain English: We load all WP options in $all_options. We copy options from $all_options to $plugin_order_options if their name contains plugin_order_. We print $plugin_order_options. We scratch our head, unhappy with the size of … Read more

Creates only one table and not the other

dbdelta demands that: You must put each field on its own line in your SQL statement. You must have two spaces between the words PRIMARY KEY and the definition of your primary key. You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY. You must … Read more

Sum of Custom Meta written by Authour

Maybe not the most elegant solution $authorPost = get_posts(array(‘author’ => 1));foreach ($catPost as $post) { setup_postdata($post); $ids[] = get_the_ID(); } $idList = implode(“,”, $ids); //turn the array into a comma delimited list $meta_key = ‘post_view’; $allview = $wpdb->get_var($wpdb->prepare(” SELECT sum(meta_value) FROM $wpdb->postmeta WHERE meta_key = %s AND post_id in (” . $idList . “)”, $meta_key)); … Read more

Custom database query to validate data

Assuming that all of your sql column names are correct, something like this should work: if(isset($_POST[‘submit’])){ global $wpdb; $tablename= $wpdb . ‘form_subscribe’; $myrows = $wpdb->get_var( $wpdb->prepare(“SELECT email FROM $tablename WHERE email=%s LIMIT 1″, $_POST[’email’])); if(empty($myrows)){ $data=array( ‘name’ => $_POST[‘fullname’], ‘age’ => $_POST[‘age’], ’email’ => $_POST[’email’] ); $wpdb->insert( $tablename, $data); } else { $status=”User already subscribed”; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)