MySql database help for a plugin

Hi @ntechi:

I think this is what you are looking for:

$sql =<<< SQL
SELECT
  id
FROM
  myrp_ratings AS rat,
  INNER JOIN wp_comments AS com ON com.comment_ID = rat.comment_id
WHERE 1=1
  AND com.comment_author_email="%s"
  AND rat.value != '0'
  AND rat.value != '1'
LIMIT
 1
SQL;
$sql = $wpdb->prepare($sql,'[email protected]');
$id = $wpdb->get_var($sql);
if (is_null($id)) {
  $wpdb->query("INSERT INTO `" . $wpdb->myrp_ratings . "`(`ID`, `category_id`, `post_id`, `comment_id`, `value`, `outof`, `weighted`) VALUES('', '{$name}', '{$postID}', '-1', '{$value}', '{$outof}', '" . ($value/$outof) . "')");    
}

Note how I formatted the SQL so you could actually read it? (though admittedly I didn’t go to the effort with the INSERT.) Also, note how I used $wpdb->prepare() to ensure that no SQL injection attacks were used from invalid email addresses? (Your plugin developer unfortunately did not do the same.)

Also be careful modifying plugins; if you do you need to change the version number to something huge like 999 to ensure you or another user doesn’t accidentally overwrite your changes when the vendor updates their plugin. Best if possible to get them to incorporate your changes into the next release of their plugin.