Saturday, 10 February 2018

mysql - Unexpected T_CONSTANT_ENCAPSED_STRING error in SQL Query




I am getting an unexpected T_CONSTANT_ENCAPSED_STRING error in the following SQL query:



mysql_query (UPDATE 'wp_posts' SET 'post_status' = 'publish' WHERE 'post_id' = '$id');


Can you guys see where the error might be?



Here is the full code in case it helps:




    $key = 'feed';
$post_ids = array(2263, 2249);

foreach ($post_ids as $id) {
$feedurl = get_post_custom_values($key, $id);
$feedurlstr = implode($feedurl);

// Ignore - it determines whether feed is live and returns $result
LiveOrNot($feedurlstr);


if ( $result == "live" ) {
mysql_query (UPDATE 'wp_posts' SET 'post_status' = 'publish' WHERE 'post_id' = '$id');
}
elseif ( $result == "notlive" ) {
mysql_query (UPDATE 'wp_posts' SET 'post_status' = 'draft' WHERE 'post_id' = '$id');
}
endif;
}

Answer




Wrap your SQL statements in quote-marks - ".



mysql_query ("UPDATE 'wp_posts' SET 'post_status' = 'publish' WHERE 'post_id' = '$id'");

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...