PHP错误从数据库中检索

时间:2014-01-02 14:51:57

标签: php html

我正在尝试在数据库中查看我的数据。我当前的代码如下,我得到的错误是解析错误:语法错误,第32行的C:\ xampp \ htdocs \ project \ viewnews.php中的文件意外结束但它看起来没问题我。任何帮助非常感谢!

代码:

<html>
  <Head>
    <Title> View News </Title>
  </head>
  <body>
  <?php
    $connection = mysql_connect('localhost', 'root', ''); 
    mysql_select_db('familease');

    $query = "SELECT * FROM news"; 
    $result = mysql_query($query);

    print("<TABLE BORDER=1 WIDTH=\"75%\" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\N");
    print("<TR ALIGN=CENTER VALIGN=TOP>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>News Date</TD>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>News Description</TD>\n");
    print("</TR>\N");

    while ($row = mysql_fetch_array($result)) {   
        print("<TR ALIGN=CENTER VALIGN=TOP>\n");
        print("<TD ALIGN=CENTER VALIGN=TOP>$Row[NewsDate]</TD>\n");
        print("<TD ALIGN=CENTER VALIGN=TOP>$Row[NewsDescription]</TD>\n");
        print("</TR>\N");

    mysql_close();
    print("</TABLE>\n"); 
  ?>
 </body>
</html>

3 个答案:

答案 0 :(得分:2)

您忘记关闭while循环:

while ($row = mysql_fetch_array($result)) {   

  print("<TR ALIGN=CENTER VALIGN=TOP>\n");
  print("<TD ALIGN=CENTER VALIGN=TOP>$Row[NewsDate]</TD>\n");
  print("<TD ALIGN=CENTER VALIGN=TOP>$Row[NewsDescription]</TD>\n");
  print("</TR>\N");

}//add this

答案 1 :(得分:0)

你应该结束头标记和句子:

 <head>
      <Title> View News </Title>
 </head> <!-- ADD THIS -->

while($row = mysql_fetch_array($result)){   
    print("<TR ALIGN=CENTER VALIGN=TOP>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>$Row[NewsDate]</TD>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>$Row[NewsDescription]</TD>\n");
    print("</TR>\N");
} // ADD THIS

答案 2 :(得分:0)

使用此代码

<html>
  <Head>
    <Title> View News </Title>
  </head>
  <body>
  <?php
    $connection = mysql_connect('localhost', 'root', ''); 
    mysql_select_db('familease');

    $query = "SELECT * FROM news"; 
    $result = mysql_query($query);

    print("<TABLE BORDER=1 WIDTH=\"75%\" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>\N");
    print("<TR ALIGN=CENTER VALIGN=TOP>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>News Date</TD>\n");
    print("<TD ALIGN=CENTER VALIGN=TOP>News Description</TD>\n");
    print("</TR>\N");

    while ($row = mysql_fetch_array($result)) {   
        print("<TR ALIGN=CENTER VALIGN=TOP>\n");
        print("<TD ALIGN=CENTER VALIGN=TOP>$Row[NewsDate]</TD>\n");
        print("<TD ALIGN=CENTER VALIGN=TOP>$Row[NewsDescription]</TD>\n");
        print("</TR>\N");
    }
    mysql_close();
    print("</TABLE>\n"); 
  ?>
 </body>
</html>