WP-PostRatings: list current user’s rated posts

Plugin questions are best asked on the plugin’s support forum. But this code is wrong: $result = $wpdb->get_results($sql) or die(mysql_error()); foreach( $results as $result ) { echo $result->name; } The foreach is backwards. Go for this (corrected $result to $results in the first line – added ‘s’): $results = $wpdb->get_results($sql) or die(mysql_error()); foreach( $results as … Read more

PHP -> SQL Query with Summing

Looking at this, I see that “Paid”, a string, isn’t in quotes. That would cause an error. You can add $wpdb->show_errors() and $wpdb->print_error() methods to reveal that, and any other mysql issues. Also when querying the database, you should use the $wpdb->prepare() method to escape and prepare your variables for query (yes $user->ID probably can’t … Read more

How to use mysql LIKE with wpdb?

According to the Codex, the delete method will not accept the LIKE operator. You’ll be better off just using the query method. $query = $wpdb->prepare(“DELETE FROM $wpdb->posts WHERE post_type=”flamingo_inbound” AND post_content LIKE %s”, ‘%’.$mail.’%’); $wpdb->query($query); Hopefully $mail doesn’t have a % or _ character otherwise you need to escape it before you build $querylike so: … Read more

How to set MYSQLI_OPT_INT_AND_FLOAT_NATIVE option

That’s why I’m wondering why is WordPress stuck to this pre-PHP-5.3 limitation. Because WordPress has made the decision to support PHP 5.2 due to the large number of hosts that continue to use it. This is an ongoing debate and there’s no point rehashing it all here. But this means that I have to know … Read more

Using $wpdb | checking entered email against existing emails in db

You shouldn’t be using mysql_num_rows() or mysql_error() when dealing with $wpdb. Even if you weren’t, mysql_error() is for database errors, and an empty result set is not a database error. If you want to know if results were returned, simply check the count() of the results: $duplicateEmail = $wpdb->get_results($emailTest, OBJECT); if ( count( $duplicateEmail ) … Read more

Display category names on edit user profile using $wpdb

The $wpdb->query() method doesn’t return query results but a count on how many rows were affected by the query. To get the results you have to user the $wpdb->get_results($sqlString) method and then iterate over it. <?php function custom_user_profile_fields($profileuser) { ?> <h1>Select a Category</h1> <select name=”category”> <?php global $wpdb; $terms = $wpdb->get_results( “SELECT name FROM wp_terms” … Read more

wpdb Cannot Update column in Database

First, an observation: the line highlighted below is correct as per your logic? This query will set the dstatus and downloadname fields in a row as $_POST[‘dstatuschange’] and $_POST[‘dlname’] if downloadname field is the ‘dlname’ string. Maybe you wanted to put the $_POST[‘dlname’] variable in your WHERE condition? Second, wordpress custom POSTs work much better … Read more

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