Unexpected T_CONSTANT_ENCAPSED_STRING error in SQL Query

扶醉桌前 提交于 2019-12-25 04:34:16

问题


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;
    }

回答1:


Wrap your SQL statements in quote-marks - ".

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



回答2:


mysql_query() takes a string. PHP is looking for constants interspersed with strings, which is not valid PHP grammer.

You need to delimit your strings, ' and " are popular choices, but there is also Heredoc syntax.

Read more about strings in PHP.



来源:https://stackoverflow.com/questions/5333823/unexpected-t-constant-encapsed-string-error-in-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!