显示聊天消息时出错

时间:2015-08-09 11:27:02

标签: php html chat

我试图创建一个聊天室作为练习,我的代码有一个奇怪的行为: (PS:与wampserver一起运行)

<?php
    header('Content-Type: application/x-www-form-urlencoded');
    try{
        $pdo_options[PDO::ATTR_ERRMODE]=PDO::ERRMODE_EXCEPTION;
        $bdd = new PDO('mysql:host=localhost;dbname=test','root','',$pdo_options);
        $msg = $bdd -> query('SELECT * FROM chatroom ORDER BY heure LIMIT 0,10');
        while($current = $msg->fetch()){
?>
            <div class='messages' ><?php echo $current['id']; ?></div><br/>
<?php
        }
        $msg->closeCursor();
    }
    catch(Exception $e){
        die('Erreur:'.$e->getMessage());
    }
?>

我得到了这个:

  

查询(&#39; SELECT * FROM聊天室ORDER BY heure LIMIT 0,10&#39;);   while($ current = $ msg-&gt; fetch()){?&gt;

     

closeCursor(); } catch(Exception $ e){die(&#39; Erreur:&#39;。$ e-&gt; getMessage());   }?&gt;

我哪里错了?

。某处必须存在语法错误,但我无法找到它。

1 个答案:

答案 0 :(得分:0)

我不知道为什么,但是我将文件保存为html页面(之前点击它,没问题)我将其保存为php文件,现在它可以正常工作。

相关问题