0

I am trying to compare urls in mysql but the query returns results matching any url.

Here is my query.

SELECT
  a.comment_ID, 
  a.comment_post_ID, 
  a.comment_content, 
  a.comment_date_gmt,  
  a.comment_author_url, 
  b.post_title, b.ID
 FROM 
   `wp_comments` a, 
   `wp_posts` b
 WHERE 
   a.comment_post_ID = b.ID
  AND 
   ('a.comment_author_email' = '$email'
   OR 
    'a.comment_author_url' = '$url')
  AND a.comment_approved = 1
 GROUP BY a.comment_ID
 ORDER BY a.comment_ID DESC

Thanks!

edit: full query

3
  • Consider revising this condition AND ('a.comment_author_email' = '$email' OR 'a.comment_author_url' = '$url') This returns true for either the author's email or the URL provided. What values are you passing? Commented Jan 5, 2012 at 10:31
  • if possible, send us this query with values and not variables, will make it easier to help =) Commented Jan 5, 2012 at 10:36
  • Here is almost the full code... pastebin.com/QJmPfd0e Commented Jan 5, 2012 at 10:51

2 Answers 2

2

In your query, make sure you replace all the ' (single quote) characters with the ` (backtick) character.

Sign up to request clarification or add additional context in comments.

Comments

0

Tips:

  • Remove ' around php variable
  • Write backticks ` around table attributes instead of '
  • may be use of INNER JOIN can make thing easier

TRY this

$qry = " SELECT { watever} FROM  `wp_comments` a,
         INNER JOIN  `wp_posts` b ON `a`.`comment_post_ID` = `b`.`ID`
         WHERE
              `a`.`comment_author_email` = '".$email."'   
          OR  `a`.`comment_author_url` ='". $url."'     
         GROUP BY `a`.`comment_ID`
         ORDER BY `a`.`comment_ID` DESC "; 

1 Comment

Same result. Just returns any rows with a url in the comment_author_url :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.