【问题标题】:php syntax error, unexpected T_VARIABLE, expecting ',' or ';' on line 29 [closed]php 语法错误,意外的 T_VARIABLE,需要 ',' 或 ';'在第 29 行 [关闭]
【发布时间】:2013-01-14 09:29:07
【问题描述】:

我正在尝试在一个简单的博客中回显我的数据库中的信息。 现在它只是行不通。无论我尝试什么。 我试图自己弄清楚,但我陷入了一个错误。

php 语法错误,意外的 T_VARIABLE,需要 ',' 或 ';'第 29 行

我只是找不到解决方案.. 希望你们能帮助我。我被困在这里好几个小时都快疯了。

require('config.inc.php');
require('template.inc.php');
require('functions.inc.php');

$db_host = "***********";
$db_username = "************0";
$db_pass = "*********";
$db_name = "****************";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to        mysql");
@mysql_select_db("$db_name") or die ("no database");

$title=$_POST['title'];
$contents=$_POST['contents'];
$author=$_POST['author'];
$date=$_POST['date'];
$date = strftime("%b %d, %y", strtotime($date));

$sqlcreate = mysql_query("INSERT INTO blog (date, title, contents, author)
            VALUES(now(),'$title','$contents','$author')");
$query="SELECT * FROM tablename";
$result=mysql_query($query);
htmlOpenen('Voeg nieuwe post toe');
while ($result=mysql_query($query) ) {
echo'
<span class="post">
    <h1>'$result['title'];'</h1>
    <h2>'$result['date'];'</h2>
    <p>'$result['contents'];'</p>
    <h3>'$result['author'];'</h3>
';
}
htmlSluiten();
mysql_close();

【问题讨论】:

标签: php mysql


【解决方案1】:

你忘记了你的连接器:

echo'
<span class="post">
    <h1>'$result['title'];'</h1>
    <h2>'$result['date'];'</h2>
    <p>'$result['contents'];'</p>
    <h3>'$result['author'];'</h3>
';

应该是

echo'
<span class="post">
    <h1>'.$result['title'].'</h1>
    <h2>'.$result['date'].'</h2>
    <p>'.$result['contents'].'</p>
    <h3>'.$result['author'].'</h3>
';

【讨论】:

  • 谢谢,现在可以解决了。但是每次我刷新我的页面时,它只是将最后一篇文章再次放入我的数据库中,而不是再次出现。有什么办法可以防止这种情况发生吗?
猜你喜欢
  • 1970-01-01
  • 2013-03-10
  • 2012-02-26
  • 2012-08-25
  • 2011-11-07
  • 1970-01-01
  • 1970-01-01
  • 2012-01-14
相关资源
最近更新 更多