Does anyone sees any fault?

<?php 
             $sql = 'SELECT * FROM messages';
$result = $database->sql_query($sql);

while ($row = $database->sql_fetchrow($result))
{
   echo $row['message'];
}
                ?>

and my database connection

$database = mysql_select_db(DB_DATABASE) or die(mysql_error());

$database = mysql_select_db(DB_DATABASE)

That returns a resource.

$database->sql_query($sql);

This implies an object.

Where did you get that code? I think you are mixing up different solutions. Check the PHP code snippets, there are samples for MySQL, MySQLi and PDO.

I believe that it should look something like this:

$my_conn = new mysqli('localhost', 'user name', 'password', 'database name');
$sql = "SELECT * FROM messages";
$result = $my_conn->query($sql);
while ($obj = $result->fetch_object()) {
    echo = $obj->message;
}

I could easily be wrong though ...

hope this helps,

Simon.

use this piece of code and replace dbname with your database name

<?php
mysql_connect("localhost","root","");
mysql_select_db("dbname");
$qry = mysql_query("SELECT * FROM messages");
while ($row = mysql_fetch_array($qry))
{
   echo $row['message'];?><br /><?php
}
?>

hope this helps you.

Yes it helped thanks very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.