dongweng6241 2013-11-05 09:20
浏览 23

你的MySQL语法中有一个错误 - 在一个简单的查询中

So I am trying to replicate a simple blogging system I made a month back, But the query no longer works on my new site Here is the code

  <?php
function BlogPosts() {
$sql = 'SELECT * FROM "blog-posts" WHERE BlogDeleted = 0';
$value = mysql_query($sql);
if(!$value){
    die("<h1>QUERY ERROR IN BLOG_POSTS: </h1>". mysql_error());
}
while($n = mysql_fetch_array($value, MYSQL_ASSOC)){
    ?>
    <h3><?php echo "{$n['BlogTitle']}"; ?></h3>
   <p><?php echo "{$n['BlogData']}"; ?></p>
   <b class="blog-user"><?php echo "entry by {$n['BlogUser']} on {$n['BlogTime']}"; ?></b>
<?php
}

} //END FUNCTION BlogPosts
?>

The full error is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"blog-posts" WHERE BlogDeleted = 0' at line 1
EDIT: Fixed the error by adding the ` to blog-posts :)

  • 写回答

1条回答 默认 最新

  • dtcd27183 2013-11-05 09:21
    关注

    In your query,

    "blog-posts"
    

    should be

    `blog-posts`
    

    Normally, you can eschew the ` characters, but the hyphen in your table name requires them.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制