Add $wpdb->prepare() to SQL statements to address security vulnerabilities

Added $wpdb->prepare() to each database query to avoid SQL injection attacks.