1

I'm trying to echo my information from my database in a simple blog. Now it just won't work. Whatever I try. I'm trying to figure it out myself but I am stuck behind a single error.

php syntax error, unexpected T_VARIABLE, expecting ',' or ';' on line 29

I just can't find a solution for it.. Hope you guys can help me. I am getting pretty insane of being stuck for hours here.

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();
gaborsch
  • 15,408
  • 6
  • 37
  • 48
Jos
  • 11
  • 1
  • 3
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – John Conde Jan 30 '13 at 14:18
  • 2
    Also, please don't give away your DB credentials to everybody – danronmoon Jan 30 '13 at 14:21
  • I hope the database credentials are just placeholders.. – HenningCash Jan 30 '13 at 14:21

1 Answers1

3

You forgot your concatentors:

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

should be

echo'
<span class="post">
    <h1>'.$result['title'].'</h1>
    <h2>'.$result['date'].'</h2>
    <p>'.$result['contents'].'</p>
    <h3>'.$result['author'].'</h3>
';
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Thanks, it works sort off now. But everytime I refresh my page it just puts the last post in my database again and than in shows up again. Is there some way to prevent this? – Jos Jan 30 '13 at 14:26