Problem with $wpdb->get_results
-
I am building a custom plugin. It has it’s own DB table (columns: id,postid,unique,url).
I built a function which contains this:
global $wpdb; $table = $wpdb->prefix."mypluginstable"; $unique = $_GET['uniqueid']; $query = $wpdb->prepare("SELECT * FROM ".$table." WHERE unique=".$unique.""); $query2 = $wpdb->get_results($query); print_r($query2);I’ve added the function’s to INIT like:
add_action('init', 'my_cool_function_name');However I get this error displayed instead of the print_r:
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘unique=680605’ at line 1]
SELECT * FROM wp_mypluginstable WHERE unique=680605I’ve tried using single quotes (‘) around the word unique (in unique=…) and also the $unique variable in the Mysql command.
The topic ‘Problem with $wpdb->get_results’ is closed to new replies.