Quote Originally Posted by stefin View Post
http://php.flashwebhost.com/stefin/mysql.php

Code:
<?php 


$db_server = '127.0.0.1'; 
$db_user = 'fwhphp_user'; 
$db_password = 'k5BJRaX6SFbs'; 
$db_name = 'fwhphp_db'; 


$mysqli = new mysqli($db_server, $db_user, $db_password, $db_name); 


if ($mysqli->connect_errno) { 
    echo 'Connect failed: ' . $mysqli->connect_error; 
    exit(); 
} 


$sql = 'SELECT * FROM `chat`'; 
$result = $mysqli->query($sql); 


echo '<p>MySQL have returned ' . $result->num_rows . ' records.</p>'; 


echo '<br>'; 
echo '<hr>'; 


foreach ($result as $row) { 
    echo '<b>' .  $row['name'] . '</b> says : ' . $row['message']; 
    echo '<br>'; 
    echo '<hr>'; 
}
Congratulation on first to try the MySQL script and post :)

Due to PHP version change, original code did not work, to fix.

Find

PHP Code:
foreach ($result as $row) { 
    echo 
'<b>' .  $row['name'] . '</b> says : ' $row['message']; 
    echo 
'<br>'
    echo 
'<hr>'

Replace With

PHP Code:
while ($chat $result->fetch_object()) {
    echo 
'<b>' .  $chat->name '</b> says : ' $chat->message;
    echo 
'<br>';
    echo 
'<hr>';


while() loop, we will learn more about it tomorrow. For now, just use it. It is some what like foreach.