-1

I'm trying to pass check to see if a field is NULL or empty:

 $query = $this->pdo->prepare('SELECT * FROM `' . $this->table . '` WHERE `wp_permalink` IS NOT NULL AND `wp_permalink` <> "" AND `id` != 2 AND `ga_page_views` != ' . $nogo . ' ORDER BY ga_page_views DESC LIMIT 6');

How can I fix the syntax error for wp_permalink <> ""? Thank you for your help. I am still learning.

Daniel Dudas
  • 2,972
  • 3
  • 27
  • 39
devManMan
  • 99
  • 8

2 Answers2

2

change the code like this.

$query = $this->pdo->prepare('SELECT * FROM `' . $this->table . '` WHERE `wp_permalink` IS NOT NULL AND `wp_permalink` <> \'\' AND `id` != 2 AND `ga_page_views` != ' . $nogo . ' ORDER BY ga_page_views DESC LIMIT 6');

Single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally aren’t used in SQL, but that can vary from database to database.

check this link also difference between single and double quotes in SQL

How to use single quote inside an echo which is using single quote

AkhilKrishnan
  • 524
  • 5
  • 17
0

String literals are denoted by single quotes:

wp_permalink IS NOT NULL and wp_permalink <> ''
-- Single quotes-----------------------------^^
Mureinik
  • 297,002
  • 52
  • 306
  • 350